Statistics

Problem Statement for "SpecialStrings"

Problem Statement

A string S is called special if it satisfies the following two properties:

  • Each character in S is either '0' or '1'.
  • Whenever S = UV where both U and V are nonempty strings, U is strictly smaller than V in lexicographic order.

For example, the string S = "00101" is special because we have "0" < "0101", "00" < "101", "001" < "01", and "0010" < "1".

You are given a String current that is guaranteed to be special. Let N be the length of current. Consider the lexicographically sorted list of all special strings of length N. Compute and return the string that comes immediatelly after current in this list. If current happens to be the last string in the list, return an empty String instead.

Definition

Class:
SpecialStrings
Method:
findNext
Parameters:
String
Returns:
String
Method signature:
String findNext(String current)
(be sure your method is public)

Notes

  • Given two different strings U and V, the string U precedes the string V in lexicographic order if one of two conditions is satisfied: Either U is a proper prefix of V, or there is an integer x such that U and V have the same first x characters, and the x+1th character in U is smaller than the x+1th character in V.

Constraints

  • current will contain between 1 and 50 characters, inclusive.
  • current will be a special string.

Examples

  1. "01"

    Returns: ""

    "01" is the only special string of length 2.

  2. "00101"

    Returns: "00111"

    The special strings of length 5 are "00001", "00011", "00101", "00111", "01011", "01111".

  3. "0010111"

    Returns: "0011011"

  4. "000010001001011"

    Returns: "000010001001101"

  5. "01101111011110111"

    Returns: "01101111011111111"

  6. "0"

    Returns: "1"

  7. "001111111111111111111111"

    Returns: "010101010101010101010111"

  8. "0111111111111111111111111111"

    Returns: ""

  9. "0001111111111111111111111111111111111111111"

    Returns: "0010010010010010010010010010010010010010011"

  10. "010101010101010101010101010101011111"

    Returns: "010101010101010101010101010101101011"

  11. "000000001010110110100110010000011"

    Returns: "000000001010110110100110010000101"

  12. "000010100011111001001"

    Returns: "000010100011111001011"

  13. "00000010000011110011111010001001011011"

    Returns: "00000010000011110011111010001001011101"

  14. "00000111110111001101000110101"

    Returns: "00000111110111001101000110111"

  15. "00001110110101111011001010000111111101110011"

    Returns: "00001110110101111011001010000111111101110101"

  16. "00011011011111111010111011011"

    Returns: "00011011011111111010111011101"

  17. "0000001001111000101100001000001110000101"

    Returns: "0000001001111000101100001000001110000111"

  18. "000001100001101010010101"

    Returns: "000001100001101010010111"

  19. "0001110100100101010101011"

    Returns: "0001110100100101010101101"

  20. "000001001011101011010111011"

    Returns: "000001001011101011010111101"

  21. "00100111101001010101011010011"

    Returns: "00100111101001010101011010101"

  22. "00001010100010101011001001"

    Returns: "00001010100010101011001011"

  23. "0000011010010110001100111101101000010100011110111"

    Returns: "0000011010010110001100111101101000010100011111001"

  24. "00011110101110011110100011111011001110111"

    Returns: "00011110101110011110100011111011001111001"

  25. "000001100101100001101101010001110011111111101011"

    Returns: "000001100101100001101101010001110011111111101101"

  26. "0000110100011010111101101011100101101101111"

    Returns: "0000110100011010111101101011100101101110001"

  27. "00000001001111110100001111000001000101100011011"

    Returns: "00000001001111110100001111000001000101100011101"

  28. "0001001011111111111010111101111101001"

    Returns: "0001001011111111111010111101111101011"

  29. "000000110100100000111001010011101000010101011101"

    Returns: "000000110100100000111001010011101000010101011111"

  30. "00000011010111001100010001101001101001111111"

    Returns: "00000011010111001100010001101001101010000011"

  31. "00001010001100101011110010111110011101111"

    Returns: "00001010001100101011110010111110011110001"

  32. "000000001111001000010111101001111011"

    Returns: "000000001111001000010111101001111101"

  33. "001011011101110111111111"

    Returns: "001011011101111001011101"

  34. "00000100110110110101010111101010001111010010101"

    Returns: "00000100110110110101010111101010001111010010111"

  35. "00001111011110111111011"

    Returns: "00001111011110111111101"

  36. "0101010110101111111011110101111110101010111011111"

    Returns: "0101010110101111111011110101111110101010111101011"

  37. "0101110101110111011010111111111101011111"

    Returns: "0101110101110111011010111111111101101111"

  38. "010111011011110111011010111111110110111111"

    Returns: "010111011011110111011010111111110111011011"

  39. "01010111011111110111110110101101101111111"

    Returns: "01010111011111110111110110101101110101111"

  40. "010111111101111111110111111111111101111011011111"

    Returns: "010111111101111111110111111111111101111011101111"

  41. "0101011101011101110101110101101011011011101111"

    Returns: "0101011101011101110101110101101011011011110111"

  42. "0101010101010111011011010111011110111111011"

    Returns: "0101010101010111011011010111011110111111111"

  43. "010101011011101101111111010111110101011110111111"

    Returns: "010101011011101101111111010111110101011111010111"

  44. "0101101011111111011011110110110101110111"

    Returns: "0101101011111111011011110110110101111011"

  45. "01011101111110110101111111111011111011111"

    Returns: "01011101111110110101111111111011111101111"

  46. "000111110010110011011011101001111001001010101011"

    Returns: "000111110010110011011011101001111001001010101101"

  47. "0001101010001111010110010100111010101010001111101"

    Returns: "0001101010001111010110010100111010101010001111111"

  48. "000110001111110011101100011001111101001010111"

    Returns: "000110001111110011101100011001111101001011001"

  49. "000111001010110010100111101001001001011100110011"

    Returns: "000111001010110010100111101001001001011100110101"

  50. "000110111001010001101111101111101001111110101111"

    Returns: "000110111001010001101111101111101001111110110011"

  51. "00011011000111111001010111010111011111011"

    Returns: "00011011000111111001010111010111011111101"

  52. "00011001011111100100011001100110110110101"

    Returns: "00011001011111100100011001100110110110111"

  53. "0001101010111101110100110110101100111101"

    Returns: "0001101010111101110100110110101100111111"

  54. "00011010111010011011010111101101100110011"

    Returns: "00011010111010011011010111101101100110101"

  55. "00011010111101101010111010111101010010101"

    Returns: "00011010111101101010111010111101010010111"

  56. "0001101011011110110011001101110110111011011010101"

    Returns: "0001101011011110110011001101110110111011011010111"

  57. "000110001111010111000110101100111000111101"

    Returns: "000110001111010111000110101100111000111111"

  58. "000110010010110110101010111110100101100101001"

    Returns: "000110010010110110101010111110100101100101011"

  59. "0001110010110110101111001000111001101111101110011"

    Returns: "0001110010110110101111001000111001101111101110101"

  60. "0001101100011011101111010111101110011110111111"

    Returns: "0001101100011011101111010111101110011111000111"

  61. "0001100101111110100100110100101010010010111"

    Returns: "0001100101111110100100110100101010010011001"

  62. "000110011110101011101001110001110101101000111"

    Returns: "000110011110101011101001110001110101101001001"

  63. "0001100101101100111000111101110101011101100101001"

    Returns: "0001100101101100111000111101110101011101100101011"

  64. "0001101110010101001011110001111111001101"

    Returns: "0001101110010101001011110001111111001111"

  65. "000111100111011101101010110011011101001010111"

    Returns: "000111100111011101101010110011011101001011001"

  66. "000110100100100111100011111101010111110111"

    Returns: "000110100100100111100011111101010111111001"

  67. "000110111111001001101010111110011100111001"

    Returns: "000110111111001001101010111110011100111011"

  68. "00011111010111010101001010111110011001101001"

    Returns: "00011111010111010101001010111110011001101011"

  69. "000110101111110101010010011110110111111111101101"

    Returns: "000110101111110101010010011110110111111111101111"

  70. "000111101010100101001101111000111110110101101"

    Returns: "000111101010100101001101111000111110110101111"

  71. "01111111111111111111111111111111111111111111111111"

    Returns: ""

  72. "011111111111111111111111111111111111111111"

    Returns: ""

  73. "01111111111111111111111101111111111111111111111111"

    Returns: "01111111111111111111111111111111111111111111111111"

  74. "1"

    Returns: ""

  75. "00111111111111111111111111111111111111111111111111"

    Returns: "01010101010101010101010101010101010101010101010111"

  76. "0011111111111111111111111111111111111111111111"

    Returns: "0101010101010101010101010101010101010101010111"

  77. "00000000000000001000000000000000100100011101110001"

    Returns: "00000000000000001000000000000000100100011101110011"

  78. "010101010101010101010111111111111111111111111"

    Returns: "010101010101010101011010101010101010101011011"

  79. "00111111111111111111111111111111111111111111111"

    Returns: "01010101010101010101010101010101010101010101011"

  80. "011011110111101111111111111111111111111111111111"

    Returns: "011011110111110110111101111101101111011111011111"

  81. "0110111101111011111111111111111111111111111111111"

    Returns: "0110111101111101101111011111011011110111110111111"

  82. "01111111111111111111111111111111111111111"

    Returns: ""

  83. "01101111"

    Returns: "01111111"

  84. "0011111111111111111111111111111111111111111111111"

    Returns: "0101010101010101010101010101010101010101010101011"

  85. "00010011011111"

    Returns: "00010011100011"

  86. "0011011111"

    Returns: "0011101011"

  87. "0000000000000000001100111"

    Returns: "0000000000000000001101001"

  88. "0000001000000100000010000001000000100000010000011"

    Returns: "0000001000000100000010000001000000100000010000101"

  89. "00000000000000000000000000000000000000000000000001"

    Returns: "00000000000000000000000000000000000000000000000011"

  90. "010111111111111111111111111111111111111111111111"

    Returns: "011011011011011011011011011011011011011011011111"

  91. "00000000000000000000000000000000001"

    Returns: "00000000000000000000000000000000011"

  92. "01011111111111111111111111111111111111111111111111"

    Returns: "01101101101101101101101101101101101101101101101111"

  93. "001100111111"

    Returns: "001101001111"

  94. "0001111111111111111111111111111111111111111111111"

    Returns: "0010010010010010010010010010010010010010010010011"

  95. "00000001111"

    Returns: "00000010001"

  96. "0000011111111"

    Returns: "0000100001001"

  97. "000110111"

    Returns: "000111001"

  98. "0000000010000000011111111111111111111111111111111"

    Returns: "0000000010000000100000000100000001000000001000001"


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: