A PIN-style puzzle asks for k different digits from 1 to 9 that add up to n.
Write digitPicks(k, n) that returns every such group of digits. Write each group sorted ascending and list the groups in sorted order (compare first digits, then second digits, and so on). Return [] if there are none.
Input: k = 3, n = 7 Output: [[1,2,4]]
1 + 2 + 4 = 7 is the only way to add 3 different digits to 7.
Input: k = 3, n = 9 Output: [[1,2,6],[1,3,5],[2,3,4]]
Three groups of 3 different digits add up to 9.
1 <= k <= 91 <= n <= 60Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #305 Distinct Digits to a Target. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.