• I just thought that this is what was really missing here: Some more test cases, to make sure that it really works as expected.

    Interestingly enough, the tests for the edge cases reveal how the current solution differs from the original implementation, which is the way how negative as well as very large input resulting in overflow is handled. While the current implementation throws a NumberFormatException in those cases, the original version of the algorithm would not throw at all and instead produce the following results:

    input output
    -1 -1
    -2_147_483_648 126_087_180 (the Integer.MIN_VALUE case)
    2_144_847_412 -2_147_482_884
    2_147_483_647 -1_126_087_180 (the Integer.MAX_VALUE case)
  • You can use reverse method on StringBuffer.

  • Is there a better way to do it?

  • What "$" stands for?