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
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
"01"
Returns: ""
"01" is the only special string of length 2.
"00101"
Returns: "00111"
The special strings of length 5 are "00001", "00011", "00101", "00111", "01011", "01111".
"0010111"
Returns: "0011011"
"000010001001011"
Returns: "000010001001101"
"01101111011110111"
Returns: "01101111011111111"
"0"
Returns: "1"
"001111111111111111111111"
Returns: "010101010101010101010111"
"0111111111111111111111111111"
Returns: ""
"0001111111111111111111111111111111111111111"
Returns: "0010010010010010010010010010010010010010011"
"010101010101010101010101010101011111"
Returns: "010101010101010101010101010101101011"
"000000001010110110100110010000011"
Returns: "000000001010110110100110010000101"
"000010100011111001001"
Returns: "000010100011111001011"
"00000010000011110011111010001001011011"
Returns: "00000010000011110011111010001001011101"
"00000111110111001101000110101"
Returns: "00000111110111001101000110111"
"00001110110101111011001010000111111101110011"
Returns: "00001110110101111011001010000111111101110101"
"00011011011111111010111011011"
Returns: "00011011011111111010111011101"
"0000001001111000101100001000001110000101"
Returns: "0000001001111000101100001000001110000111"
"000001100001101010010101"
Returns: "000001100001101010010111"
"0001110100100101010101011"
Returns: "0001110100100101010101101"
"000001001011101011010111011"
Returns: "000001001011101011010111101"
"00100111101001010101011010011"
Returns: "00100111101001010101011010101"
"00001010100010101011001001"
Returns: "00001010100010101011001011"
"0000011010010110001100111101101000010100011110111"
Returns: "0000011010010110001100111101101000010100011111001"
"00011110101110011110100011111011001110111"
Returns: "00011110101110011110100011111011001111001"
"000001100101100001101101010001110011111111101011"
Returns: "000001100101100001101101010001110011111111101101"
"0000110100011010111101101011100101101101111"
Returns: "0000110100011010111101101011100101101110001"
"00000001001111110100001111000001000101100011011"
Returns: "00000001001111110100001111000001000101100011101"
"0001001011111111111010111101111101001"
Returns: "0001001011111111111010111101111101011"
"000000110100100000111001010011101000010101011101"
Returns: "000000110100100000111001010011101000010101011111"
"00000011010111001100010001101001101001111111"
Returns: "00000011010111001100010001101001101010000011"
"00001010001100101011110010111110011101111"
Returns: "00001010001100101011110010111110011110001"
"000000001111001000010111101001111011"
Returns: "000000001111001000010111101001111101"
"001011011101110111111111"
Returns: "001011011101111001011101"
"00000100110110110101010111101010001111010010101"
Returns: "00000100110110110101010111101010001111010010111"
"00001111011110111111011"
Returns: "00001111011110111111101"
"0101010110101111111011110101111110101010111011111"
Returns: "0101010110101111111011110101111110101010111101011"
"0101110101110111011010111111111101011111"
Returns: "0101110101110111011010111111111101101111"
"010111011011110111011010111111110110111111"
Returns: "010111011011110111011010111111110111011011"
"01010111011111110111110110101101101111111"
Returns: "01010111011111110111110110101101110101111"
"010111111101111111110111111111111101111011011111"
Returns: "010111111101111111110111111111111101111011101111"
"0101011101011101110101110101101011011011101111"
Returns: "0101011101011101110101110101101011011011110111"
"0101010101010111011011010111011110111111011"
Returns: "0101010101010111011011010111011110111111111"
"010101011011101101111111010111110101011110111111"
Returns: "010101011011101101111111010111110101011111010111"
"0101101011111111011011110110110101110111"
Returns: "0101101011111111011011110110110101111011"
"01011101111110110101111111111011111011111"
Returns: "01011101111110110101111111111011111101111"
"000111110010110011011011101001111001001010101011"
Returns: "000111110010110011011011101001111001001010101101"
"0001101010001111010110010100111010101010001111101"
Returns: "0001101010001111010110010100111010101010001111111"
"000110001111110011101100011001111101001010111"
Returns: "000110001111110011101100011001111101001011001"
"000111001010110010100111101001001001011100110011"
Returns: "000111001010110010100111101001001001011100110101"
"000110111001010001101111101111101001111110101111"
Returns: "000110111001010001101111101111101001111110110011"
"00011011000111111001010111010111011111011"
Returns: "00011011000111111001010111010111011111101"
"00011001011111100100011001100110110110101"
Returns: "00011001011111100100011001100110110110111"
"0001101010111101110100110110101100111101"
Returns: "0001101010111101110100110110101100111111"
"00011010111010011011010111101101100110011"
Returns: "00011010111010011011010111101101100110101"
"00011010111101101010111010111101010010101"
Returns: "00011010111101101010111010111101010010111"
"0001101011011110110011001101110110111011011010101"
Returns: "0001101011011110110011001101110110111011011010111"
"000110001111010111000110101100111000111101"
Returns: "000110001111010111000110101100111000111111"
"000110010010110110101010111110100101100101001"
Returns: "000110010010110110101010111110100101100101011"
"0001110010110110101111001000111001101111101110011"
Returns: "0001110010110110101111001000111001101111101110101"
"0001101100011011101111010111101110011110111111"
Returns: "0001101100011011101111010111101110011111000111"
"0001100101111110100100110100101010010010111"
Returns: "0001100101111110100100110100101010010011001"
"000110011110101011101001110001110101101000111"
Returns: "000110011110101011101001110001110101101001001"
"0001100101101100111000111101110101011101100101001"
Returns: "0001100101101100111000111101110101011101100101011"
"0001101110010101001011110001111111001101"
Returns: "0001101110010101001011110001111111001111"
"000111100111011101101010110011011101001010111"
Returns: "000111100111011101101010110011011101001011001"
"000110100100100111100011111101010111110111"
Returns: "000110100100100111100011111101010111111001"
"000110111111001001101010111110011100111001"
Returns: "000110111111001001101010111110011100111011"
"00011111010111010101001010111110011001101001"
Returns: "00011111010111010101001010111110011001101011"
"000110101111110101010010011110110111111111101101"
Returns: "000110101111110101010010011110110111111111101111"
"000111101010100101001101111000111110110101101"
Returns: "000111101010100101001101111000111110110101111"
"01111111111111111111111111111111111111111111111111"
Returns: ""
"011111111111111111111111111111111111111111"
Returns: ""
"01111111111111111111111101111111111111111111111111"
Returns: "01111111111111111111111111111111111111111111111111"
"1"
Returns: ""
"00111111111111111111111111111111111111111111111111"
Returns: "01010101010101010101010101010101010101010101010111"
"0011111111111111111111111111111111111111111111"
Returns: "0101010101010101010101010101010101010101010111"
"00000000000000001000000000000000100100011101110001"
Returns: "00000000000000001000000000000000100100011101110011"
"010101010101010101010111111111111111111111111"
Returns: "010101010101010101011010101010101010101011011"
"00111111111111111111111111111111111111111111111"
Returns: "01010101010101010101010101010101010101010101011"
"011011110111101111111111111111111111111111111111"
Returns: "011011110111110110111101111101101111011111011111"
"0110111101111011111111111111111111111111111111111"
Returns: "0110111101111101101111011111011011110111110111111"
"01111111111111111111111111111111111111111"
Returns: ""
"01101111"
Returns: "01111111"
"0011111111111111111111111111111111111111111111111"
Returns: "0101010101010101010101010101010101010101010101011"
"00010011011111"
Returns: "00010011100011"
"0011011111"
Returns: "0011101011"
"0000000000000000001100111"
Returns: "0000000000000000001101001"
"0000001000000100000010000001000000100000010000011"
Returns: "0000001000000100000010000001000000100000010000101"
"00000000000000000000000000000000000000000000000001"
Returns: "00000000000000000000000000000000000000000000000011"
"010111111111111111111111111111111111111111111111"
Returns: "011011011011011011011011011011011011011011011111"
"00000000000000000000000000000000001"
Returns: "00000000000000000000000000000000011"
"01011111111111111111111111111111111111111111111111"
Returns: "01101101101101101101101101101101101101101101101111"
"001100111111"
Returns: "001101001111"
"0001111111111111111111111111111111111111111111111"
Returns: "0010010010010010010010010010010010010010010010011"
"00000001111"
Returns: "00000010001"
"0000011111111"
Returns: "0000100001001"
"000110111"
Returns: "000111001"
"0000000010000000011111111111111111111111111111111"
Returns: "0000000010000000100000000100000001000000001000001"