Started to build solution with complexity O(n*logn)