Problem Statement
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
{"???"}
3
Returns: 1000
Every 3 digit string is possible.
{"9??","??7"}
3
Returns: 10
The first digit must be 9 and the last must be 7.
{"9??","??7"}
4
Returns: 0
The patterns say that the string must have length 3.
{"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.
{ "??????????????????????????????????????????????????", "?????????????????????????????????????????????????9", "?????????????????????????????????????????????????8" }
50
Returns: 0
{ "??????????????????????????????????????????????????" }
49
Returns: 0
{ "-?????" }
4
Returns: 0
{"????-"}
3
Returns: 0
{"12345678901234567890", "????????????????????" }
20
Returns: 1
{"1234567890??????????", "??????????1234567890" }
20
Returns: 1
{"1234567890??????????", "123456789??????????1" }
20
Returns: 1000000000
{ "123456-", "-123456" }
6
Returns: 1
{"777-","-777"}
3
Returns: 1
{"777-","-777"}
4
Returns: 1
{"777-","-777"}
5
Returns: 1
{"777-","-777"}
6
Returns: 1
{"777-","-777"}
7
Returns: 10
{"777-","-777"}
8
Returns: 100
{"777-","-777"}
2
Returns: 0
{ "????????????????????-", "-????????????????????", "9??????????????????????????", "?8?????????????????????????", "??7????????????????????????", "???6???????????????????????", "????5??????????????????????", "?????4?????????????????????", "??????3????????????????????", "?????432???????????????????", "?????43210123456?-", "-98765"}
27
Returns: 1000000
{ "??????????????????????????????", "12345678901234567?????????????", "?????????????????1234567890123" }
30
Returns: 1
{"??"}
1
Returns: 0
{ "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890", "12345678901234567890123456789012345678901234567890" }
50
Returns: 1
{ "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
{"???????7-", "-8???????"}
15
Returns: 0
{"???3-","-3???"}
7
Returns: 1000000
{"???3-","-4???"}
8
Returns: 1000000
{"???3-","-4???"}
7
Returns: 0
{"1234567-","-1234567"}
7
Returns: 1
{"1234567-","-1234567"}
14
Returns: 1
{"1234567-","-1234567"}
8
Returns: 0
{"1234", "1234" }
4
Returns: 1
{"1234" }
3
Returns: 0
{"5", "5" }
1
Returns: 1
{"-???" }
3
Returns: 1000
{"-9", "-9?", "-??9", "-?9", "9?9-" }
8
Returns: 10000
{"9999", "999" }
3
Returns: 0