Skip to content

Practice Inverse Coin Change

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3592
LeetCode Problem

Inverse Coin Change

Problem Statement

You are given a 1-indexed integer array numWays, where numWays[i] represents the number of ways to select a total amount i using an infinite supply of some fixed coin denominations. Each denomination is a positive integer with value at most numWays.length. However, the exact coin denominations have been lost. Your task is to recover the set of denominations that could have resulted in the given numWays array. Return a sorted array containing unique integers which represents this set of denominations. If no such set exists, return an empty array.

Source: Inverse Coin Change on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
numWays = [0,1,0,2,0,3,0,4,0,5]
Output
[2,4,6]

# Example 2

Input
numWays = [1,2,2,3,4]
Output
[1,2,5]

# Example 3

Input
numWays = [1,2,3,4,15]
Output
[]

Constraints

1 <= numWays.length <= 100
0 <= numWays[i] <= 2 * 10^8

Related LeetCode Problems

Practice more problems similar to Inverse Coin Change.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.