Statistics

Problem Statement for "DigitMask"

Problem Statement

You will be given a list of patterns. Each pattern will contain only digits ('0'-'9'), question marks ('?'), and may potentially begin or end (but not both) with a hyphen ('-'). You must return the number of strings of length len that match all of the patterns. A digit must be matched with the same digit. A question mark can be matched with any digit. If the pattern ends with a hyphen, the pattern is describing a prefix. Similarly, if the pattern begins with a hyphen it describes a suffix. If there are no hyphens, the matched string must have the same length as the pattern. Said differently, a hyphen matches 0 or more digits.

Definition

Class:
DigitMask
Method:
howMany
Parameters:
String[], int
Returns:
int
Method signature:
int howMany(String[] patterns, int len)
(be sure your method is public)

Constraints

  • patterns will contain between 1 and 50 elements, inclusive.
  • Each element of patterns will contain between 1 and 50 characters, inclusive.
  • Each character in patterns will be a digit ('0'-'9'), a question mark ('?'), or a hyphen ('-');
  • Each element of patterns will contain at most 1 hyphen, and it must occur at the beginning or the end of the element.
  • len will be between 1 and 50, inclusive.
  • The return value will be between 0 and 1,000,000,000, inclusive.
  • No element of patterns will be "-" (quotes for clarity).

Examples

  1. {"???"}

    3

    Returns: 1000

    Every 3 digit string is possible.

  2. {"9??","??7"}

    3

    Returns: 10

    The first digit must be 9 and the last must be 7.

  3. {"9??","??7"}

    4

    Returns: 0

    The patterns say that the string must have length 3.

  4. {"9??-","-???7"}

    4

    Returns: 100

    The first pattern says the string begins with a 9 and has at least 3 digits. The second pattern says the string ends with a 7 and has at least 4 digits.

  5. { "??????????????????????????????????????????????????", "?????????????????????????????????????????????????9", "?????????????????????????????????????????????????8" }

    50

    Returns: 0

  6. { "??????????????????????????????????????????????????" }

    49

    Returns: 0

  7. { "-?????" }

    4

    Returns: 0

  8. {"????-"}

    3

    Returns: 0

  9. {"12345678901234567890", "????????????????????" }

    20

    Returns: 1

  10. {"1234567890??????????", "??????????1234567890" }

    20

    Returns: 1

  11. {"1234567890??????????", "123456789??????????1" }

    20

    Returns: 1000000000

  12. { "123456-", "-123456" }

    6

    Returns: 1

  13. {"777-","-777"}

    3

    Returns: 1

  14. {"777-","-777"}

    4

    Returns: 1

  15. {"777-","-777"}

    5

    Returns: 1

  16. {"777-","-777"}

    6

    Returns: 1

  17. {"777-","-777"}

    7

    Returns: 10

  18. {"777-","-777"}

    8

    Returns: 100

  19. {"777-","-777"}

    2

    Returns: 0

  20. { "????????????????????-", "-????????????????????", "9??????????????????????????", "?8?????????????????????????", "??7????????????????????????", "???6???????????????????????", "????5??????????????????????", "?????4?????????????????????", "??????3????????????????????", "?????432???????????????????", "?????43210123456?-", "-98765"}

    27

    Returns: 1000000

  21. { "??????????????????????????????", "12345678901234567?????????????", "?????????????????1234567890123" }

    30

    Returns: 1

  22. {"??"}

    1

    Returns: 0

  23. { "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890" }

    50

    Returns: 1

  24. { "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890" }

    50

    Returns: 1

  25. {"???????7-", "-8???????"}

    15

    Returns: 0

  26. {"???3-","-3???"}

    7

    Returns: 1000000

  27. {"???3-","-4???"}

    8

    Returns: 1000000

  28. {"???3-","-4???"}

    7

    Returns: 0

  29. {"1234567-","-1234567"}

    7

    Returns: 1

  30. {"1234567-","-1234567"}

    14

    Returns: 1

  31. {"1234567-","-1234567"}

    8

    Returns: 0

  32. {"1234", "1234" }

    4

    Returns: 1

  33. {"1234" }

    3

    Returns: 0

  34. {"5", "5" }

    1

    Returns: 1

  35. {"-???" }

    3

    Returns: 1000

  36. {"-9", "-9?", "-??9", "-?9", "9?9-" }

    8

    Returns: 10000

  37. {"9999", "999" }

    3

    Returns: 0


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: