Inverse Coin Change - Problem

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.

Input & Output

Example 1 — Basic Case
$ Input: numWays = [1,1,2,2,3,4]
Output: [1,2]
💡 Note: With coins [1,2]: ways to make 1=1 (coin 1), ways to make 2=1 (coin 2), ways to make 3=2 (1+1+1 or 1+2), ways to make 4=2 (1+1+1+1 or 2+2), ways to make 5=3 (add coin 1 or 2 to make 4 or 3), ways to make 6=4 (multiple combinations)
Example 2 — Single Coin
$ Input: numWays = [1,0,0,1]
Output: [1,4]
💡 Note: With coins [1,4]: ways to make 1=1 (coin 1), ways to make 2=0 (impossible), ways to make 3=0 (impossible), ways to make 4=1 (coin 4)
Example 3 — No Valid Set
$ Input: numWays = [1,2,3]
Output: []
💡 Note: No valid coin set can produce this pattern - the growth is too rapid for any reasonable denomination set

Constraints

  • 1 ≤ numWays.length ≤ 1000
  • 0 ≤ numWays[i] ≤ 1000
  • Each denomination value is at most numWays.length

Visualization

Tap to expand
Inverse Coin Change: Recover Lost DenominationsInput numWays:112234amt=1amt=2amt=3amt=4amt=5amt=6Analyze PatternRecovered Coins:12
Understanding the Visualization
1
Input Analysis
Given numWays array representing ways to make each amount
2
Pattern Detection
Identify where new denominations are introduced
3
Denomination Recovery
Extract the original coin denominations
Key Takeaway
🎯 Key Insight: Analyze when actual ways exceed expected ways to identify required denominations
Asked in
Google 15 Amazon 12 Microsoft 8
23.0K Views
Medium Frequency
~35 min Avg. Time
890 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen