Using a priority queue

Can’t we simply use a priority queue here? That would take a single traversal O(n) (because it takes O(n) to create a priority queue) and make implementation a bit easier?

  1. doing that the complexity goes to nlogn since insertion in priority queue takes logn time and inserting n elements would mean nlogn
  2. how will u implement it using a priority queue each time u only get the top element which is either min or max which would mean it will be tough to keep track of multiple sequences together

hey @ankurguria if your doubt is solved, please mark it as resolved

@ankurguria hey, if your doubt is solved
please mark it as resolved

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.