You are viewing a single comment's thread. Return to all comments →
It is rightly placed under queue. I solved it using queue in O(n).
Hint: Use two queue
It's impossible to solve this in O(n). You sorted the input - that's O(n log n).
You can sort in O(N) using Count Sort, the numbers in the array are < 10^6