I have used vector and then sorted it whenever user in typing 2 but it would cause log N time everytime so i tried it with PBDS but still getting WA. And i am unable to understand the solution and use of priority queue
Getting WA with policy based data structures and vector too
Hi @pandeykshitiz05_0ec52bd954a1fc73,
You can’t use PBDS here, as PBDS stores unique elements, and the rocket distances might be same.
Yes, please. Share your approach and intuition
@pandeykshitiz05_0ec52bd954a1fc73,
I updated your code,
Intuition,
At any given point of time, you only need k greatest rocket distances. So, for a query of type 1, just push the element in the priority queue and check if its size is greater than k or not.
If yes, then pop the topmost element, therefore, the size of the priority queue will always equal to k.
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.