We can also solve this problem in O(n log n) using Divide and conquer. But I guess the intended solution is much more elegant.
We can also solve this problem in O(n log n) using Divide and conquer. But I guess the intended solution is much more elegant.