Count non-decreasing arrays by digit sums
MicrosoftSoftware Engineer · Technical ScreenLast updated
This question evaluates combinatorics and constrained counting skills, including reasoning about digit-sum properties, monotonic sequences, modular arithmetic, and efficient algorithm design within the Coding & Algorithms domain.
You are given an array required_sums of length n. Count how many non-decreasing arrays result[1..n] of integers satisfy all of the following: (
- for each i, digit_sum(result[i]) = required_sums[i]; (
- for each i, result[i] ≤ 5000; and (
- for i > 1, result[i] ≥ result[i−1]. Two arrays are distinct if they differ at any index. Return the count modulo 1,000,000,007. Describe an efficient algorithm and analyze its time and space complexity.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.