The Full Counting Sort

  • + 2 comments

    Some tips that may be helpful. If you are getting TLE (time limit exceeded)

    1. String concat operator '+' is very slow. Use StringBuilder instead.

    2. Try not to print one by one. Make long strings first and then print.

    My algorithm is pretty straightforward :

    I have a Map where key is Integer and value is StringBuilder. As read my input, I put each string ('-' if first half). After done reading inputs, I get a keySet(), put it in a List<Integer>, sort the list, and traverse the list and use each element to get value from map. Each value retreived from the map is appended together and print the result at the end.

    Passed all test cases and last one took 2.03 seconds.