I came across this problem in codility, and it seemd a little bit too hard especially with the O(n*logn) time complexity and O(n) space complexity.
This is the problem link https://codility.com/programmers/task/zig_zag_escape/.
Can anybody help with their ideas?