TLE on 2nd test Case

https://ide.codingblocks.com/s/71373

I am getting TLE in my second test case if you can give me some hint

here for updation, you traverse through complete list.

SO your complexity is O(qn)
You need to solve it in O(q
log(n))
Hint - use MaxPriority Queue of Size K

1 Like

Thank you… Got the answer

1 Like