ORIGINAL CODING QUESTION
Ways to pay a stipend
An intern stipend of exactly total rupees is paid using notes of the given distinct denominations, with unlimited notes of each kind. Count the different collections of notes that pay it; the order in which notes are handed over does not matter. Return the count modulo 1,000,000,007. A total of 0 is paid in one way, with no notes.
Original exercise · medium. Editorial role relevance does not imply a company has asked this question.
Input and output
n, then n distinct denominations, then the total.
Constraints
1 ≤ n ≤ 10; 1 ≤ denomination ≤ 100; 0 ≤ total ≤ 1000.
Example 1
Input
3 2 3 5 10
Output
4
Collections: 5+5, 2+3+5, 2+2+3+3 and 2+2+2+2+2.
Example 2
Input
2 4 6 9
Output
0
Even notes can never make an odd total.
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
Counting ordered sequences would count 2+3 and 3+2 twice.
Hint 2
Fix the order of denominations: decide how many of the first kind, then the next, and so on.
Hint 3
Loop denominations on the outside and totals on the inside: ways[t] += ways[t - note].
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →