Count Non-Decreasing Arrays with Prescribed Digit Sums
Company: Microsoft
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Online Assessment
Overview: Count non-decreasing arrays whose values are at most 5000 and match specified decimal digit sums, returning the total modulo 1000000007.
Read the full Microsoft Software Engineer interview experience this question came from
Constraints
- 1 <= len(requiredSum) <= 5000.
- Every requiredSum[i] is an integer from 1 through 31.
- Each counted result value is an integer from 1 through 5000, and equal adjacent values are allowed.
- Return the count modulo 1000000007.
Examples
Input: ([1],)
Expected Output: 4
Explanation: Exactly 1, 10, 100, and 1000 have digit sum one.
Input: ([1, 1],)
Expected Output: 10
Explanation: Choosing a non-decreasing pair from four eligible values with repetition gives ten arrays.
Hints
- A valid value at a position must match that position’s required digit sum.
- Equal adjacent values are permitted by the non-decreasing condition.