Statistics

Problem Statement for "TelephoneNumbers"

Problem Statement

Your company has received the contract to implement the new telephone system on the moon, where all telephone numbers will have 7 hexadecimal digits (see notes). The distance between two telephone numbers is the number of corresponding digits that differ. For example, the distance between 1b100fa and 11b0ffa is 3, because the 2nd, 3rd, and 5th digits (counting from the left) are different. In order to avoid wrong numbers, every pair of telephone numbers will have a distance of at least separation between them. Your policy for allocating telephone numbers is simple: each time a new number is required, the smallest possible number is assigned such that these conditions are preserved.

Your company is going to award a special prize to the person who is assigned the kth telephone number (k is 1-based). Return this number as a string of exactly 7 hexadecimal digits: '0' - '9' and lowercase 'a' - 'f'. The constraints guarantee that k is small enough for the prize to be awarded before it becomes impossible to allocate new numbers.

Definition

Class:
TelephoneNumbers
Method:
kthNumber
Parameters:
int, int
Returns:
String
Method signature:
String kthNumber(int separation, int k)
(be sure your method is public)

Notes

  • Hexadecimal is base 16 (compared to "normal" numbers, which are base 10). The lowercase letters 'a' - 'f' are used to represent the digits with values 10 - 15. For example, the hexadecimal number 'af' is the same as the decimal number 10 * 16 + 15 = 175.

Constraints

  • separation will be between 1 and 3, inclusive.
  • k will be between 1 and 300,000, inclusive.

Examples

  1. 1

    5

    Returns: "0000004"

    The first five phone numbers are simply 0000000, 0000001, 0000002, 0000003 and 0000004.

  2. 2

    17

    Returns: "0000101"

    The first sixteen phone numbers are 00000?? for ? = 0, 1, ..., f.

  3. 3

    33

    Returns: "0002023"

  4. 1

    1

    Returns: "0000000"

  5. 1

    2

    Returns: "0000001"

  6. 1

    15

    Returns: "000000e"

  7. 1

    16

    Returns: "000000f"

  8. 1

    255

    Returns: "00000fe"

  9. 1

    256

    Returns: "00000ff"

  10. 1

    257

    Returns: "0000100"

  11. 1

    4095

    Returns: "0000ffe"

  12. 1

    4096

    Returns: "0000fff"

  13. 1

    4097

    Returns: "0001000"

  14. 1

    5012

    Returns: "0001393"

  15. 1

    61440

    Returns: "000efff"

  16. 1

    65244

    Returns: "000fedb"

  17. 1

    65535

    Returns: "000fffe"

  18. 1

    65536

    Returns: "000ffff"

  19. 1

    65537

    Returns: "0010000"

  20. 1

    300000

    Returns: "00493df"

  21. 1

    299999

    Returns: "00493de"

  22. 2

    1

    Returns: "0000000"

  23. 2

    2

    Returns: "0000011"

  24. 2

    3

    Returns: "0000022"

  25. 2

    15

    Returns: "00000ee"

  26. 2

    16

    Returns: "00000ff"

  27. 2

    17

    Returns: "0000101"

  28. 2

    18

    Returns: "0000110"

  29. 2

    40

    Returns: "0000275"

  30. 2

    41

    Returns: "000028a"

  31. 2

    49

    Returns: "0000303"

  32. 2

    65535

    Returns: "00fffe1"

  33. 2

    65536

    Returns: "00ffff0"

  34. 2

    100000

    Returns: "01869f9"

  35. 2

    200000

    Returns: "030d3f2"

  36. 2

    127715

    Returns: "01f2e20"

  37. 2

    209716

    Returns: "0333333"

  38. 2

    300000

    Returns: "0493dfc"

  39. 3

    1

    Returns: "0000000"

  40. 3

    2

    Returns: "0000111"

  41. 3

    3

    Returns: "0000222"

  42. 3

    15

    Returns: "0000eee"

  43. 3

    16

    Returns: "0000fff"

  44. 3

    17

    Returns: "0001012"

  45. 3

    18

    Returns: "0001103"

  46. 3

    40

    Returns: "0002754"

  47. 3

    41

    Returns: "00028ab"

  48. 3

    49

    Returns: "0003031"

  49. 3

    65535

    Returns: "0fffe10"

  50. 3

    65536

    Returns: "0ffff01"

  51. 3

    100000

    Returns: "1869f92"

  52. 3

    200000

    Returns: "30d3f2a"

  53. 3

    127715

    Returns: "1f2e200"

  54. 3

    209716

    Returns: "3333333"

  55. 3

    300000

    Returns: "493dfc6"

  56. 3

    299843

    Returns: "4934285"

  57. 3

    291457

    Returns: "4728095"

  58. 3

    276301

    Returns: "4374c84"

  59. 3

    42342

    Returns: "0a565c2"

  60. 3

    123456

    Returns: "1e23f1f"

  61. 3

    298777

    Returns: "48f18a9"

  62. 3

    291777

    Returns: "473c0ce"

  63. 3

    299998

    Returns: "493dde4"

  64. 3

    123123

    Returns: "1e0f227"

  65. 3

    298765

    Returns: "48f0cff"


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: