Leetcode 2952: Minimum Number of Coins to be Added

grid47
grid47
Exploring patterns and algorithms
Jan 16, 2024 5 min read

You are given a list of coin denominations and a target value. Your task is to determine the minimum number of new coin denominations you need to add to the list, so that every integer value from 1 to the target can be formed as a sum of some subset of the coins. A coin denomination can be added if it helps form values that cannot be formed using the existing coins.
Problem
Approach
Steps
Complexity
Input: A list of integers `coins` representing the denominations of the available coins and an integer `target` representing the target value.
Example: coins = [1, 4, 10], target = 19
Constraints:
• 1 <= target <= 100000
• 1 <= coins.length <= 100000
• 1 <= coins[i] <= target
Output: Return the minimum number of coins needed to be added to the list so that every integer value from 1 to the target can be formed.
Example: 2
Constraints:
Goal: Determine the minimum number of coin denominations to add so that all integers from 1 to the target can be formed.
Steps:
• Sort the existing coins.
• Start with a sum of 0 and try to form all numbers up to the target.
• If a coin can contribute to the current sum, add it to the sum.
• If the coin cannot contribute, add the next required coin (current_sum + 1).
• Repeat this until the sum reaches the target.
Goal: The input list must have at least 1 coin, and the target must be a positive integer.
Steps:
• 1 <= target <= 100000
• 1 <= coins.length <= 100000
• 1 <= coins[i] <= target
Assumptions:
• The list of coins is initially sorted.
Input: Input: coins = [1, 4, 10], target = 19
Explanation: We need to add coins with values 2 and 8 to make it possible to form all integers from 1 to 19.

Link to LeetCode Lab


LeetCode Solutions Library / DSA Sheets / Course Catalog
comments powered by Disqus