Problem · String

Without Whitespaces

Learn this problem
HardPostman logoPostmanINTERNOA

Problem 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) → long

Examples

Example 1

n = 7c = 1234567k = 9s = "1234567"return = 64

There 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 = 2

The two valid arrays are [12] and [1, 2].

Constraints

  • 1 ≤ n = s.length ≤ 10^4
  • 1 ≤ c ≤ 10^9
  • 1 ≤ k ≤ 18
  • s contains only decimal digits.

More Postman problems

drafts saved locally
public long countArrays(int n, long c, int k, String s) {
    // write your code here
}
n7
c1234567
k9
s"1234567"
expected64
checking account