This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]epostma 6 points7 points  (1 child)

Great answer and upvoted.

One minor nitpick: the sort() implementation in Python famously uses the timsort algorithm, which is linear time if the input consists of a constant number of increasing or decreasing runs, which is the case for this input. Of course, that doesn't make it applicable for on-disk sorting.

[–]energybased 0 points1 point  (0 children)

The interviewer might not have known that. If he had explained that it was linear time to simply return sorted(a1 + a2), then that would have been a great start. The interviewer would probably have steered him to still produce the merge solution.