Pages

CodeEval Time to eat

Given a string contains a blank separated list of timestamps in format HH:MM:SS, return it sorted in descending order. This is the CodeEval problem #214.

I'm using Python 3 as implementation language, that leads naturally to a trivial solution. If line is the string containing the input string, the output could be generated by a one-liner:
' '.join(sorted(line.split(), reverse=True))
The split() function converts the input line to a list of timestamps, the sorted() function rearrange the list in a ordered fashion, passing True as its reverse parameter, instead of the natural, increasing, order I ask it to use the decreasing one. Joining on a blank I get back the required result.

Even though it is a kind of an overkilling, I put the test case and the actual python solution on GitHub.

No comments:

Post a Comment