Hi, I wanted to solve this question in O(N) but couldn't think of it. I did it in O(N logN ) using priority queue but can somebody provide me O(N) solution.
http://photoeditor.funphotobox.com/photo-editor-online
The link of question is not opening now, so I have shared the pic of question.