Problem · String
Without Whitespaces
Learn this problemProblem statement
You are given integers n, c, and k, together with a decimal digit string s of length n.
Count how many arrays of nonnegative integers could have produced s when their usual decimal representations were printed consecutively without separators. Every array element must be no greater than c, and no element may have a leading zero except for the value 0 itself.
The array may contain any positive number of elements. Return the number of valid arrays modulo 10^k.
Function
countArrays(n: int, c: long, k: int, s: String) → longExamples
Example 1
n = 7c = 1234567k = 9s = "1234567"return = 64There are 64 valid ways to split the seven-digit string into one or more values no greater than 1234567. The result remains 64 modulo 10^9.
Example 2
n = 2c = 12k = 3s = "12"return = 2The two valid arrays are [12] and [1, 2].
Constraints
1 ≤ n = s.length ≤ 10^41 ≤ c ≤ 10^91 ≤ k ≤ 18scontains only decimal digits.
More Postman problems
- Configuration SystemOA · Seen Sep 2020
- Large ResponsesOA · Seen Sep 2020
- Minimum Swaps to Sort an ArrayOA · Seen Aug 2020
- Validate IP AddressOA · Seen Aug 2020
- Maximum Laptop Rating in a Price RangeOA · Seen Aug 2019
- Encode and Decode a String StreamONSITE INTERVIEW
- Group Duplicate Files by ContentONSITE INTERVIEW