How can I implement a function increment(string) that given string A produces string B where:
- B > A (using Java’s compareTo logic)
- There exists NO C where B > C > A
And the same for decrement(string) that given string A produces string B where:
- B < A (using Java’s compareTo logic)
- There exists NO C where B < C < A
EDIT
As pointed out in comments, this question is impossible to answer without some restrictions. The restriction is that you cannot append/remove new characters to/from the string unless it’s to handle under/over flow.
Increment is straightforward:
B = A + "\u0000".Decrement is impossible; the greatest string that is less than
"Y", for example, is"X\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF\uFFFF...".