Pick K Distinct Keypad Digits That Add Up to a Checksum
Last updated: November 29, 2026
Quick Overview
A Nest keypad test generates PINs made of k distinct digits from 1 to 9 whose digits sum to n. Return every such set of digits in ascending order.
0
0
0 solved
A Nest keypad test generates PINs made of k distinct digits from 1 to 9 whose digits sum to n. Return every such set of digits in ascending order.
A small Google online assessment problem with a fixed, tiny search space. The grader checks clean recursion with two stopping conditions (count and sum) and simple pruning.
What the Interviewer Expects
- Uses ascending digits to avoid duplicate sets
- Stops when either k digits are used or the sum is exceeded
- Breaks early when the next digit exceeds the remaining sum
- Notes the search space is at most C(9, k)
- Handles impossible inputs such as n > 45
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you allow digit 0 but forbid a leading zero in the PIN?
- How many sets exist for k = 3 and n = 15?
- How would you return permutations (actual PINs) rather than sets?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: integers k (1 to 9) and n.
- Output: all ascending lists of k distinct digits in 1..9 summing to n. Example: k = 3, n = 9 gives
[1,2,6],[1,3,5],[2,3,4]. - If none exist, return an emp...
High-Level Design
Choose digits in increasing order starting at 1. State is (next_digit, remaining_sum) plus the path. If the path has k digits, record it only when the remaining sum is exactly 0. While looping over ...