I enjoyed solving this one. O(N log N)