Statistics

Problem Statement for "LicensePlate"

Problem Statement

Almost every different government in the world has a different method of assigning license plates to vehicles. In any of these systems, it is possible to take all possible plates, arrange them in lexicographical order, and number them, where the first plate is 0, the second plate is 1, etc. Your local government has decided to do this with the license plates that it issues, and right before you leave to eat lunch, you have been assigned this daunting project. So that you can actually have a warm meal today, you have decided to write a program to do this for you.

You will be given a String format, containing the format of the local license plates. Each character of format will be either an uppercase letter ('A'-'Z'), a number ('0'-'9'), a space (' '), a dash ('-'), or the lowercase letters 'u', 'n', or 'a'. If the character is a 'u', it means that any uppercase letter can be used in that place. If the character is an 'n', it means that any number can be used in that place. If the character is an 'a', it means that any uppercase letter or number can be used in that place. If the character is not a lowercase letter, then the character in that spot must be the one used in format. For instance, if the format was "AB-una", then "AB-C52" and "AB-D3G" would be legal license plates, but "AC-D3G", "AB-111", and "AB-DEF" would not.

Given the format, you are to return the n-th earliest (0-indexed) license plate that can be formed in this system. If the n-th license plate cannot be formed using the given format, return an empty String. Note that numbers occur earlier lexicographically than letters (e.g., '4' comes before 'B').

Definition

Class:
LicensePlate
Method:
getPlate
Parameters:
String, int
Returns:
String
Method signature:
String getPlate(String format, int n)
(be sure your method is public)

Constraints

  • format will contain between 1 and 50 characters, inclusive.
  • Each character of format will be an uppercase letter ('A'-'Z'), a number ('0'-'9'), a space (' '), a hyphen ('-'), or the lowercase letters 'a', 'n', or 'u'.
  • n will be between 0 and 2^31-1, inclusive.

Examples

  1. "ABu"

    2

    Returns: "ABC"

    The license plates in this format are "ABA", "ABB", "ABC", "ABD", etc. We return the 2nd (0-based) element in this list, which is "ABC".

  2. "ABn"

    2

    Returns: "AB2"

  3. "ABa"

    12

    Returns: "ABC"

    Remember that numbers come first in lexicographical order.

  4. "A BC"

    2

    Returns: ""

    There are only 1 possible license plate in this format ("ABC"), so we must return a blank plate.

  5. "una"

    8732

    Returns: "Y2K"

  6. "ABa DEuF-GHuJ KL-aMNaa5390u"

    1345876

    Returns: "AB0 DEAF-GHBJ KL-3MNXW5390M"

  7. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

    2147483647

    Returns: "00000000000000000000000000000000000000000000ZIK0ZJ"

  8. "nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn"

    2147483647

    Returns: "00000000000000000000000000000000000000002147483647"

  9. "uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu"

    2147483647

    Returns: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGYTISYX"

  10. "n"

    10

    Returns: ""

  11. "a"

    36

    Returns: ""

  12. "u"

    26

    Returns: ""

  13. "u"

    25

    Returns: "Z"

  14. "a"

    35

    Returns: "Z"

  15. "n"

    9

    Returns: "9"

  16. "ABCD "

    0

    Returns: "ABCD "

  17. " "

    1

    Returns: ""

  18. "-"

    0

    Returns: "-"

  19. "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCD0123456789"

    0

    Returns: "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCD0123456789"

  20. "-a-a-a-a-a-a-a-a-a-a-"

    2000000000

    Returns: "-0-0-0-0-X-2-Q-X-V-K-"

  21. "ABuaCDunEFn"

    123456789

    Returns: ""

  22. "aauuunn"

    2123456789

    Returns: "XKECD89"

  23. "auuuunn"

    2123456789

    Returns: ""

  24. "4VJ-34 uPGV8DHU8UQ4FMLX0YGRL3XuQCN"

    1125898167

    Returns: ""

  25. "AF XRPN25nSJOHU9YARGOuZuT2V4uuXHBSn0nIL2I-a5"

    356426808

    Returns: "AF XRPN250SJOHU9YARGOFZQT2V4LZXHBS404IL2I-O5"

  26. "W62annu0EUM7GU4a7nO2WLnauL "

    1687926652

    Returns: "W62019G0EUM7GU4X74O2WL0FWL "

  27. "nY49J7a"

    1947346619

    Returns: ""

  28. "XZLaPZTDVLAaa4JA1NSWP0XaNOMCJ8uuRMnunPuX6"

    111537764

    Returns: "XZL0PZTDVLA004JA1NSWP0X2NOMCJ8LLRM9R4PAX6"

  29. "9a-a2ISI5A-9VJD40n5WTBSPCnX53"

    1350573793

    Returns: ""

  30. "W-FWXUn-HH6A8nMW6NL"

    1504569917

    Returns: ""

  31. "S-O18uQTa8u7n4N0 IaBunnFQWu-uM8QFEunFYWuO4aUQJC"

    552473416

    Returns: "S-O18AQT08A704N0 I0BA03FQWJ-IM8QFEE9FYWJO4SUQJC"

  32. "CS5GSa4uuXaMPRZZY1aEHuZuuDRHM8nUK"

    1704365084

    Returns: "CS5GS04AHXHMPRZZY1DEHDZAIDRHM84UK"

  33. "82U 4BnAXM5GnQDD4E 5AnHQPuNuPn7F8LuWVa2CO"

    155789224

    Returns: "82U 4B0AXM5G2QDD4E 5A4HQPQNEP17F8LMWVG2CO"

  34. "NuZY2 QQaT3Qu8 nHn8S8DZ"

    1566288819

    Returns: ""

  35. "0uanXNRUauE X2-uPLnHFnUDauuA2P MW7QCC"

    777210498

    Returns: "0A00XNRU0ME X2-HPL3HF6UDNRMA2P MW7QCC"

  36. "Cana11n8nLuMXau6au8a1Haa 4TuuT6BX4EIP"

    677870460

    Returns: "C00011080LAMX0A60V8H1HQM 4TYUT6BX4EIP"

  37. "WVanA"

    31308902

    Returns: ""

  38. "au-7uWaaZa6Dn327 JVnXuI3X-3Va6Pu7L6 n-aX8089N"

    337453826

    Returns: "0A-7AW00Z06D3327 JV8XNI3X-3VG6PT7L6 7-EX8089N"

  39. "F ELRFZD8TuLV28USBIMuCG4auUaKuWXu"

    358532290

    Returns: "F ELRFZD8TALV28USBIMPCG4QQULKFWXM"

  40. "OnYZ-BVG4IuG8GXEN7Su9O1566KO2ALAEu5uDLMn1RCR571B"

    2037770478

    Returns: ""

  41. "IPXaDM6T"

    2077211388

    Returns: ""

  42. "1BZ-COuL7NHQaRaZG08 9BJPB"

    1452888574

    Returns: ""

  43. "anZP58nYnTZKKuZ7un6YMPOGGXV34nU1BDBauFVa4E"

    345367818

    Returns: "00ZP580Y0TZKKDZ7Y46YMPOGGXV349U1BDBISFVI4E"

  44. "HuaFu2"

    845563291

    Returns: ""

  45. "uI7M-Mu0Q0LY-SU-4a-SIHXVGT"

    1941727088

    Returns: ""

  46. "E0aLu359a-RWT9EML4Hu"

    1255387090

    Returns: ""

  47. "YnPF137Rn"

    35756851

    Returns: ""

  48. "aMa3An"

    1385414639

    Returns: ""

  49. "OLUHVuZJE4uOMF 0uXPO2QV281QnYHaaYRIDQaS030nn-n48WD"

    1626250262

    Returns: "OLUHVAZJE4AOMF 0DXPO2QV281Q4YHUTYRIDQMS03026-248WD"

  50. "19nRSQQn3PBJa"

    1603591171

    Returns: ""

  51. "NMnaa1BDWAaO2C2n9UnJuP7DAEK"

    262178224

    Returns: "NM25T1BDWA1O2C279U7JWP7DAEK"

  52. "7aWDaZI67U"

    992028067

    Returns: ""

  53. "R5Z0QZTaX8naZHBaZZaO10Z5JuTnQ na02ZAJBCnuGa1UnVD"

    1431742587

    Returns: "R5Z0QZT0X800ZHB0ZZ0O10Z5JET2Q 4W02ZAJBC3YGQ1U7VD"

  54. "nnn-nn-nnnn"

    2

    Returns: "000-00-0002"

    The (ficticious) social security number of C. Montgomery Burns from the Simpsons.

  55. "uu"

    675

    Returns: "ZZ"

  56. "uu"

    676

    Returns: ""

  57. "an"

    359

    Returns: "Z9"

  58. "an"

    361

    Returns: ""

  59. "aaaaaaaaaaaaaaaaaaaaaaa"

    100000000

    Returns: "000000000000000001NJCHS"

  60. "aaaaunaaaaaaaaunaaaaaaaaunaaaaaaaaunaaaaaaaaunaaaa"

    2147481777

    Returns: "0000A000000000A000000000A000000000A000000004X8JZJL"

  61. "uuuuuuuuuuuuuuuuuuuuuuuu"

    1

    Returns: "AAAAAAAAAAAAAAAAAAAAAAAB"

  62. "nnnnnnnnnnnnnnnnnnn"

    2147483647

    Returns: "0000000002147483647"

  63. "ABn"

    2

    Returns: "AB2"

  64. "a"

    36

    Returns: ""

  65. "aaaaaaaaaaaaaaaaa"

    324255345

    Returns: "000000000005D1X0X"

  66. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

    2147483647

    Returns: "00000000000000000000000000000000000000000000ZIK0ZJ"

  67. "ABC"

    0

    Returns: "ABC"

  68. "una"

    8732

    Returns: "Y2K"

  69. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

    2147483647

    Returns: "000000000000000000000000000000000000000ZIK0ZJ"

  70. "AAA"

    1

    Returns: ""

  71. "a"

    100

    Returns: ""

  72. "AAAA"

    0

    Returns: "AAAA"

  73. "aaaaaaaaaa"

    2000000000

    Returns: "0000X2QXVK"

  74. "ABa"

    12

    Returns: "ABC"

  75. "a"

    50

    Returns: ""

  76. "nnnn"

    10000

    Returns: ""

  77. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

    2147483647

    Returns: "0000000000000000000000000000000000ZIK0ZJ"

  78. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

    123

    Returns: "0000000000000000000000000000000000000000000000003F"

  79. "aaauaaaauaaaaauaaaaaaanaaaaaaaanaaauauuaaaanaaanaa"

    2147483647

    Returns: "000A0000A00000A00000000000000000000A0AA00003JUS8ZJ"

  80. "ABCD"

    0

    Returns: "ABCD"

  81. "ABaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

    2147483647

    Returns: "AB0000000000000000000000000000ZIK0ZJ"

  82. "unaunaDSAJK 46554 unnnnnn"

    4546555

    Returns: "A00A00DSAJK 46554 E546555"

  83. "aaaaaaaaaaaaaaaaaaaaaaaaaaa"

    100000000

    Returns: "0000000000000000000001NJCHS"

  84. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

    1223

    Returns: "000000000000000000000000000000000000000000000000XZ"

  85. "ABa DEuF-GHuJ KL-aMNaa5390u"

    1345876

    Returns: "AB0 DEAF-GHBJ KL-3MNXW5390M"

  86. "aaaa"

    2

    Returns: "0002"


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: