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.
https://postimg.org/image/c31iexg13/ The link of question is not opening now, so I have shared the pic of question.