Statistics

Problem Statement for "DigitStringDiv2"

Problem Statement

You are given a digit string S and a positive integer integer X. We want to select a non-empty contiguous substring of S such that:

  • The substring does not begin with the digit '0'.
  • When you convert it to a number, its value is strictly greater than X.

Two ways of selecting a substring are different if they begin or end at a different index.

Compute and return the number of ways in which we can select a substring with the above properties.

Definition

Class:
DigitStringDiv2
Method:
count
Parameters:
String, int
Returns:
int
Method signature:
int count(String S, int X)
(be sure your method is public)

Constraints

  • S will contain between 1 and 9 characters, inclusive.
  • Each character of S will be a digit ('0'-'9').
  • X will be between 0 and 777,444,111, inclusive.

Examples

  1. "0"

    1

    Returns: 0

  2. "10"

    9

    Returns: 1

  3. "471"

    47

    Returns: 2

    We can select either the substring "471" or the substring "71".

  4. "0"

    777444111

    Returns: 0

  5. "000000000"

    777444111

    Returns: 0

  6. "999999999"

    777444111

    Returns: 1

  7. "00030"

    708253

    Returns: 0

  8. "000589"

    691668

    Returns: 0

  9. "0008409"

    610805

    Returns: 0

  10. "00015496"

    307266

    Returns: 0

  11. "000953561"

    714547

    Returns: 1

  12. "45"

    0

    Returns: 3

  13. "589"

    0

    Returns: 6

  14. "8860"

    0

    Returns: 9

  15. "20463"

    0

    Returns: 11

  16. "322395"

    0

    Returns: 21

  17. "782984137"

    44633

    Returns: 14

  18. "731477481"

    25708

    Returns: 14

  19. "350085176"

    52176

    Returns: 8

  20. "203417351"

    33007

    Returns: 9

  21. "080852803"

    29582

    Returns: 7

  22. "970233950"

    84993

    Returns: 9

  23. "289775158"

    40240

    Returns: 14

  24. "528797331"

    67759

    Returns: 13

  25. "658448500"

    44534

    Returns: 15

  26. "672236426"

    24987

    Returns: 13

  27. "00007000"

    7

    Returns: 3

  28. "2222"

    97

    Returns: 3

    We can select the entire string S ("2222"). We also have two different ways to select the string "222": either we choose the first three or the last three characters of S

  29. "09"

    1

    Returns: 1

  30. "009"

    8

    Returns: 1

  31. "10100607"

    6

    Returns: 15

  32. "02355653"

    2

    Returns: 27

  33. "0011"

    1

    Returns: 1

  34. "9"

    0

    Returns: 1

  35. "009"

    1

    Returns: 1

  36. "02"

    1

    Returns: 1

  37. "1001177"

    90

    Returns: 8

  38. "1099"

    9

    Returns: 4

  39. "000000009"

    0

    Returns: 1

  40. "0022220"

    10000

    Returns: 1


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: