Recover Coins from Change Counts
Updated
Problem statement
An unknown set of distinct positive coin denominations was used in the unlimited Coin Change combinations recurrence.
You receive the completed array ways, where ways[a] is the number of order-independent combinations that form amount a. The original recurrence started with ways[0] = 1 and processed every coin in increasing denomination order.
Exactly one valid coin set exists, every denomination is at most ways.length - 1, and every count fits in a signed 64-bit integer. Recover and return the coin denominations in increasing order.
Function
recoverCoins(ways: long[]) → int[]Examples
Example 1
ways = [1,1,1,2,2,3,4]return = [1,3,5]Coins 1, 3, and 5 produce the displayed combination counts through amount 6.
Example 2
ways = [1,0,1,0,1,1]return = [2,5]Amounts 2 and 4 use coin 2, while amount 5 reveals coin 5.
Constraints
2 <= ways.length <= 2000.ways[0] = 1.- Every value is nonnegative and fits in a signed 64-bit integer.
- Exactly one set of distinct positive denominations in
[1, ways.length - 1]produces the array.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Coin Game From The EndsTekion · PHONE SCREENTekion interview questions
- Maximum-Product Subarray with an Empty ChoiceAkuna Capital · PHONE SCREENAkuna Capital interview questions
- Pascal's TriangleJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
- At Most K Jumps with Quadratic Transition CostInfosys · OAInfosys interview questions
- Jump Game with Prime-3 StepsUber · OAUber interview questions
- Maximum Score with Prime JumpsMicrosoft · OAMicrosoft interview questions
- Jump Game with Prime-3 StepsAgoda · OAAgoda interview questions
- Tree Path GCDNewton School · PHONE SCREEN
- Allocate Mailboxes with Squared DistanceLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Optimal Account BalancingAmazon · ONSITE INTERVIEW