Problem Statement
Typically, telephone numbers are sequences of digits (0-9) that all have the same length. However, some prefixes may be reserved for special purposes. This limits the total number of possible full-length telephone numbers that are available for general use in the system.
As an example, in much of the United States and Canada the local telephone numbers are 7 digits long. However, dialing 1 starts a special sequence for long distance, dialing 0 connects to the operator, and dialing 911 connects to emergency services. Thus, there are fewer than the theoretical 10,000,000 possible valid telephone numbers.
You are given the
Compute and return the number of different standard telephone numbers in the system.
Definition
- Class:
- TCPhoneHomeEasy
- Method:
- validNumbers
- Parameters:
- int, String[]
- Returns:
- int
- Method signature:
- int validNumbers(int digits, String[] specialPrefixes)
- (be sure your method is public)
Constraints
- digits will be between 1 and 7, inclusive.
- specialPrefixes will contain beteween 0 and 50 elements, inclusive.
- The length of each element of specialPrefixes will be between 1 and digits, inclusive.
- Each character of each element of specialPrefixes will be a digit ('0'...'9').
- No element of specialPrefixes will itself be a prefix of another element.
Examples
7
{ "0", "1", "911" }
Returns: 7990000
This is the example from the problem statement.
5
{ "0", "1", "911" }
Returns: 79900
Same prefixes, but with shorter phone numbers.
6
{ "1", "2", "3" }
Returns: 700000
6
{ "1", "23", "345" }
Returns: 889000
7
{}
Returns: 10000000
6
{"9633","599","11021","209453","6330","0228","95838","288019","01","72","42913","90","096","3306","631","66256","284","953","9452","998936","79471","586287"}
Returns: 964446
3
{"455","899","342","868","72","757","46","688","97","21","609","83","840","70","31","52","04","427","673","14","587","40","01","548","11"}
Returns: 858
4
{"8099","50","268","029","254","5881","6195","676"}
Returns: 9857
5
{"426","64","79175","156","23","13019","539","2729","7483","68758","9623","3024","433","478","34265","9085","226","959"}
Returns: 97246
4
{"1"}
Returns: 9000
6
{"959259"}
Returns: 999999
6
{"42","508132","99","327","8175","53452","763320","213","003951","8777","05616","85739","62","17","70","599","272","436543","387","651","268","14050","45568","9662","341977","433636","73104","758","86"}
Returns: 931634
2
{"03","32","2","51","49","47","00"}
Returns: 84
1
{}
Returns: 10
7
{"10629","9242","948","66785","45","32","07579","577","63","1351158","2654264","558799","9447","1969384","93","610258"}
Returns: 9577677
7
{"8"}
Returns: 9000000
7
{"978882","80160","86347","354098","17","04419","27064","7692","6197242","69070","8255527","710771","2288218","9791526","997","22030","94","657053","18769","685","24","90","124122","098","1120695","708","3767","683460","45135","925","88","98849","827045","54155","15607","640","91971","799482","6478","74"}
Returns: 9335715
7
{"37937","2"}
Returns: 8999900
7
{"689483","715068","96","3","75585","92408","154785","079","945687","1086","11938","136389","45","08","9785","0905"}
Returns: 8686650
7
{"859258","31","51656","4120","47","355397","27403","192","4122798","4638","6371802","4403315","222","1724565","841238","7613900","72","3822230","7803524","00379","27619","917","16274","17130","62","04509","5985","61470","05189","038655","2034","8418167","1909","434","1071746","80","334","658","52350","5038","0202","2671947","540","5737579","857624","149","30"}
Returns: 9311939
3
{"411"}
Returns: 999
Sometimes a special "prefix" is actually a full length phone number.
6
{"1", "2", "3" }
Returns: 700000
5
{"11", "9" }
Returns: 89000