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.
It is not possible to convert the strings to integers as javascript wont support integers with large sizes.
What we need to do is compare the strings, but strings are compared char by char so: 123 > 134 but 123 > 1124. It seems the only way to solve this issue is by sorting strings with equal length and progressively add them to the result.
That code basically sorts the entire array by length and starts adding the strings to a queue. When it finds a string with a larger length than the last string added to the queue, it sorts the queue and append it to the result. Then it add that last string found to the queue and repeats the process.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Big Sorting
You are viewing a single comment's thread. Return to all comments →
It is not possible to convert the strings to integers as javascript wont support integers with large sizes.
What we need to do is compare the strings, but strings are compared char by char so: 123 > 134 but 123 > 1124. It seems the only way to solve this issue is by sorting strings with equal length and progressively add them to the result.
That code basically sorts the entire array by length and starts adding the strings to a queue. When it finds a string with a larger length than the last string added to the queue, it sorts the queue and append it to the result. Then it add that last string found to the queue and repeats the process.