We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Some tips that may be helpful. If you are getting TLE (time limit exceeded)
String concat operator '+' is very slow. Use StringBuilder instead.
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.
The Full Counting Sort
You are viewing a single comment's thread. Return to all comments →
Some tips that may be helpful. If you are getting TLE (time limit exceeded)
String concat operator '+' is very slow. Use StringBuilder instead.
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 isStringBuilder
. As read my input, I put each string ('-' if first half). After done reading inputs, I get akeySet()
, put it in aList<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.