Find missing number from concatenated digits
Company: Chime
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: A coding interview question on locating a digit position within concatenated integers to find a missing number. Covers the string-parsing and combinatorial approach with a complete worked solution.
Part 1: Find Missing Number in Ordered Concatenation
Constraints
- 1 <= n <= 99
- s contains only digits
- s is formed by concatenating the numbers 1..n in increasing order with exactly one number removed
- Numbers 1-9 contribute one digit each; numbers 10-99 contribute two digits each
- s may be an empty string when n = 1
Examples
Input: (5, '1234')
Expected Output:
Explanation: The sequence should be 12345. The final number 5 is missing.
Input: (5, '1345')
Expected Output:
Explanation: The digits jump from 1 to 3, so 2 is missing.
Hints
- Walk through the numbers from 1 to n while keeping a pointer into s.
- At the first number whose string representation does not match the next characters of s, that number is the answer.
Part 2: Find Missing Number from Shuffled Concatenated Digits
Constraints
- 1 <= n <= 99
- s contains only digits
- s is a permutation of the digits from concatenating 1..n with exactly one whole number removed
- Numbers 1-9 contribute one digit each; numbers 10-99 contribute two digits each
- Test cases guarantee that exactly one value k in [1, n] matches the missing digit multiset
- s may be an empty string when n = 1
Examples
Input: (1, '')
Expected Output:
Explanation: Edge case: the only number is missing, so no digits remain.
Input: (9, '98765321')
Expected Output:
Explanation: The shuffled digits contain every digit from 1 to 9 except 4.
Hints
- Count how many times each digit 0-9 appears in all numbers from 1 to n, then subtract the counts seen in s.
- The remaining digit-frequency pattern must match the digits of the missing number.