Statistics

Problem Statement for "MissingDigits"

Problem Statement

You are opening a new hotel and are in the process of numbering the rooms. Being a superstitious person, you don't want to allow certain numbers. You are given an int[] notAllowed containing an encoded list of forbidden sequences. The ith forbidden sequence (where i is a 0-based index) is the concatenation of decimal representations of i and notAllowed[i] (both with no extra leading zeros). For example, if the 0th element of notAllowed is 33, then "033" is a forbidden sequence. A room number is not allowed if its decimal string representation, with no extra leading zeroes, contains any of the forbidden sequences as a substring. Given an int roomNumber, return "YES" if the room number is allowed, and "NO" otherwise (all quotes for clarity).

Definition

Class:
MissingDigits
Method:
isAllowed
Parameters:
int[], int
Returns:
String
Method signature:
String isAllowed(int[] notAllowed, int roomNumber)
(be sure your method is public)

Constraints

  • notAllowed will contain between 0 and 50 elements, inclusive.
  • Each element of notAllowed will be between 0 and 10000000, inclusive.
  • roomNumber will be between 0 and 10000000, inclusive.

Examples

  1. {1}

    101

    Returns: "NO"

    Since element 0 of notAllowed is 1, 01 is forbidden. Hence 101 is not a valid room number.

  2. {1,33,7}

    7133

    Returns: "NO"

    Element 1 of notAllowed is 33, so 133 is forbidden.

  3. {1,32,67}

    267

    Returns: "NO"

    Element 2 of notAllowed is 67, so 267 is forbidden.

  4. {1,33,7}

    233

    Returns: "YES"

  5. {1,33,7}

    71

    Returns: "YES"

  6. {1,33,7}

    23

    Returns: "YES"

  7. {1,33,7}

    68

    Returns: "YES"

  8. {1,33,7}

    238832

    Returns: "YES"

  9. {1,33,7}

    893398

    Returns: "YES"

  10. {}

    34

    Returns: "YES"

  11. {0}

    0

    Returns: "YES"

    "00" is forbidden, but single 0 is allowed.

  12. {1,32,67}

    123

    Returns: "YES"

  13. {0,3,1,0,8,7,5,5,2,8,4,2,2,2,0,8,9,2,4,4,5,0}

    1210010

    Returns: "NO"

  14. {0,3,1,0,8,7,5,5,2,8,4,2,2,2,0,8,9,2,4,4,5,0}

    1647555

    Returns: "NO"

  15. {0,3,1,0,8,7,5,5,2,8,4,2,2,2,0,8,9,2,4,4,5,0}

    5268252

    Returns: "NO"

  16. {1245,2481,1271,1463,557,1544,1462,1710,988,2167,1013,736,1816,702,388,207,333,27,349,1659,1818,1227,1893,1916,1430,1630,893,651,2142,987,631,2290,1267,656,1912,343,1339,1938,753,2150,576,76,801,1270,2266,2415,188,1595,1749,2019}

    192529

    Returns: "YES"

  17. {1245,2481,1271,1463,557,1544,1462,1710,988,2167, 1013,736,1816,702,388,207,333,27,349,1659,1818, 1227,1893,1916,1430,1630,893,651,2142,987,631, 2290,1267,656,1912,343,1339,1938,753,2150,576, 76,801,1270,2266,2415,188,1595,1749,2019}

    2026595

    Returns: "YES"

  18. {1245,2481,1271,1463,557,1544,1462,1710,988,2167,1013,736,1816,702,388,207,333,27,349,1659,1818,1227,1893,1916,1430,1630,893,651,2142,987,631,2290,1267,656,1912,343,1339,1938,753,2150,576,76,801,1270,2266,2415,188,1595,1749,2019}

    1825640

    Returns: "YES"

  19. {37,24,20,17,5,33,6,29,22,1,5,17,21,36,8,26,45,21,8,2,3,0,41,8,40,26,36,22,24,33,8,35,39,39,10,2,1,1,26,6,19,40,13,15,34,25,8,45,15,35}

    1334916

    Returns: "NO"

  20. {37,24,20,17,5,33,6,29,22,1,5,17,21,36,8,26,45,21,8,2,3,0,41,8,40,26,36,22,24,33,8,35,39,39,10,2,1,1,26,6,19,40,13,15,34,25,8,45,15,35}

    1143142

    Returns: "YES"

  21. {37,24,20,17,5,33,6,29,22,1,5,17,21,36,8,26,45,21,8,2,3,0,41,8,40,26,36,22,24,33,8,35,39,39,10,2,1,1,26,6,19,40,13,15,34,25,8,45,15,35}

    1746834

    Returns: "NO"

  22. {272,123,384,299,53,137,119,380,34,198,13,312,397,14,109,160,45,192,31,223,315,40,270,156,14,257,300,231,183,396,150,114,25,138,361,330,97,365,83,49,98,205,141,350,298,38,270,216,91,380}

    174380

    Returns: "YES"

  23. {272,123,384,299,53,137,119,380,34,198,13,312,397,14,109,160,45,192,31,223,315,40,270,156,14,257,300,231,183,396,150,114,25,138,361,330,97,365,83,49,98,205,141,350,298,38,270,216,91,380}

    49380

    Returns: "NO"

  24. {272,123,384,299,53,137,119,380,34,198,13,312,397,14,109,160,45,192,31,223,315,40,270,156,14,257,300,231,183,396,150,114,25,138,361,330,97,365,83,49,98,205,141,350,298,38,270,216,91,380}

    3132097

    Returns: "YES"

  25. {272,123,384,299,53,137,119,380,34,198,13,312,397,14,109,160,45,192,31,223,315,40,270,156,14,257,300,231,183,396,150,114,25,138,361,330,97,365,83,49,98,205,141,350,298,38,270,216,91,380}

    813512

    Returns: "YES"

  26. {476,437,519,542,40,132,362,141,519,330,335,624,323,226,124,567,306,339,564,521,522,405,228,207,31,467,534,372,235,131,409,528,324,126,379,478,431,523,597,336,500,102,256,129,233,268,175,546,47,262}

    9116240

    Returns: "NO"

  27. {476,437,519,542,40,132,362,141,519,330,335,624,323,226,124,567,306,339,564,521,522,405,228,207,31,467,534,372,235,131,409,528,324,126,379,478,431,523,597,336,500,102,256,129,233,268,175,546,47,262}

    241760

    Returns: "YES"

  28. {476,437,519,542,40,132,362,141,519,330,335,624,323,226,124,567,306,339,564,521,522,405,228,207,31,467,534,372,235,131,409,528,324,126,379,478,431,523,597,336,500,102,256,129,233,268,175,546,47,262}

    843220

    Returns: "YES"

  29. {62659,57965,47101,46760,47973,11931,36909,54457,53743,87711,32657,67422,56332,78184,16228,54180,571,70139,77418,48835,63790,81160,67948,79019,3868,97856,620,22121,13360,64326,85296,45390,34053,40515,24928,61715,59901,44497,94457,23642,24018,16173,20126,71730,73457,25722,39029,40940,63512,23061}

    952744

    Returns: "YES"

  30. {62659,57965,47101,46760,47973,11931,36909,54457,53743,87711,32657,67422,56332,78184,16228,54180,571,70139,77418,48835,63790,81160,67948,79019,3868,97856,620,22121,13360,64326,85296,45390,34053,40515,24928,61715,59901,44497,94457,23642,24018,16173,20126,71730,73457,25722,39029,40940,63512,23061}

    5023061

    Returns: "YES"

  31. {62659,57965,47101,46760,47973,11931,36909,54457,53743,87711,32657,67422,56332,78184,16228,54180,571,70139,77418,48835,63790,81160,67948,79019,3868,97856,620,22121,13360,64326,85296,45390,34053,40515,24928,61715,59901,44497,94457,23642,24018,16173,20126,71730,73457,25722,39029,40940,63512,23061}

    374226

    Returns: "YES"

  32. {1245,2481,1271,1463,557,1544,1462,1710,988,2167, 1013,736,1816,702,388,207,333,27,349,1659,1818, 1227,1893,1916,1430,1630,893,651,2142,987,631, 2290,1267,656,1912,343,1339,1938,753,2150,576, 76,801,1270,2266,2415,188,1595,1749,2019}

    4312703

    Returns: "NO"

  33. {1245, 2481, 1271, 1463, 557, 1544, 1462, 1710, 988, 2167, 1013, 736, 1816, 702, 388, 207, 333, 27, 349, 1659, 1818, 1227, 1893, 1916, 1430, 1630, 893, 651, 2142, 987, 631, 2290, 1267, 656, 1912, 343, 1339, 1938, 753, 2150, 576, 76, 801, 1270, 2266, 2415, 188, 1595, 1749, 2019 }

    4312703

    Returns: "NO"

  34. {1 }

    1000000

    Returns: "YES"

  35. {0 }

    101

    Returns: "YES"

  36. {34 }

    123456

    Returns: "YES"

  37. {13, 28 }

    28

    Returns: "YES"

  38. {1, 33, 7 }

    7134

    Returns: "YES"

  39. {0 }

    100

    Returns: "NO"


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: