DSA interview question
A puzzle app generates "killer sudoku" cage hints: a cage of k cells must contain distinct digits from 1 to 9 that add up to n. For each cage, the hint panel lists every possible digit set. The search space is tiny (subsets of 1–9), but it's a clean backtracking exercise: choose digits in increasing order so each set appears once, and stop as soon as the set is full or the remaining sum can't be reached.
Example: k = 3, n = 9 → [1,2,6] [1,3,5] [2,3,4].
vector<vector<int>> combinationSum3(int k, int n); // lexicographic order
Input (k, n) | Output | Explanation |
|---|---|---|
(3, 7) | [1,2,4] | The only set |
(3, 9) | [1,2,6] [1,3,5] [2,3,4] | |
(4, 1) | (none) | The smallest 4 digits already sum to 10 |
(2, 18) | (none) | The largest pair is 8 + 9 = 17 |
(9, 45) | [1,2,3,4,5,6,7,8,9] | All nine digits |
(Confirm: only digits 1–9, each at most once per combination; combinations are sets, output in lexicographic order.)
On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.
Book a free mock interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in