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.
Comparison function basically needs to return a non zero value, if first argument is less than second argument.
The function first sorts on length (smaller length == smaller number) and when length ties, is compares the string by ASCII value (i.e. the char '1' < '2'). This means it will compare the first character of one string to the first character of the second string, until they don't match returning wherether the first is smaller than the second (this is how c++ uses the < operator on strings comparing them char by char so that abc < bc)
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 →
Read the "comp" section of this page: http://www.cplusplus.com/reference/algorithm/sort/
Comparison function basically needs to return a non zero value, if first argument is less than second argument.
The function first sorts on length (smaller length == smaller number) and when length ties, is compares the string by ASCII value (i.e. the char '1' < '2'). This means it will compare the first character of one string to the first character of the second string, until they don't match returning wherether the first is smaller than the second (this is how c++ uses the < operator on strings comparing them char by char so that abc < bc)