Statistics

Problem Statement for "TCPhoneHomeEasy"

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 int digits: the length of the standard telephone numbers in the system. You are also given a String[] specialPrefixes. Each element of specialPrefixes is a string of digits that defines one reserved prefix. Standard telephone numbers cannot start with any of the reserved prefixes.

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

  1. 7

    { "0", "1", "911" }

    Returns: 7990000

    This is the example from the problem statement.

  2. 5

    { "0", "1", "911" }

    Returns: 79900

    Same prefixes, but with shorter phone numbers.

  3. 6

    { "1", "2", "3" }

    Returns: 700000

  4. 6

    { "1", "23", "345" }

    Returns: 889000

  5. 7

    {}

    Returns: 10000000

  6. 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

  7. 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

  8. 4

    {"8099","50","268","029","254","5881","6195","676"}

    Returns: 9857

  9. 5

    {"426","64","79175","156","23","13019","539","2729","7483","68758","9623","3024","433","478","34265","9085","226","959"}

    Returns: 97246

  10. 4

    {"1"}

    Returns: 9000

  11. 6

    {"959259"}

    Returns: 999999

  12. 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

  13. 2

    {"03","32","2","51","49","47","00"}

    Returns: 84

  14. 1

    {}

    Returns: 10

  15. 7

    {"10629","9242","948","66785","45","32","07579","577","63","1351158","2654264","558799","9447","1969384","93","610258"}

    Returns: 9577677

  16. 7

    {"8"}

    Returns: 9000000

  17. 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

  18. 7

    {"37937","2"}

    Returns: 8999900

  19. 7

    {"689483","715068","96","3","75585","92408","154785","079","945687","1086","11938","136389","45","08","9785","0905"}

    Returns: 8686650

  20. 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

  21. 3

    {"411"}

    Returns: 999

    Sometimes a special "prefix" is actually a full length phone number.

  22. 6

    {"1", "2", "3" }

    Returns: 700000

  23. 5

    {"11", "9" }

    Returns: 89000


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: