In the Priority Queue solution the space complexity can go up to O(N) and the Time Complexity is also effected by that. If you try this test case [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] 3 and print the size of the Priority Queue at each iteration, then you will find that the size is constantly increasing. It is because the out of bound elements will not always be at the top of the pq. So while ( i - pq.peek()[0] > k) { pq.remove(); } will not be able to remove elements that are not useful. I love your explanations. Your channel is really helpful for learners like me and many others. Waiting for you to cross 100K.
@harigovind112 жыл бұрын
That's right. I also don't think the pruning approach bounds the pq size but only keeps the desired element at the top of the heap.
@koushikkgs74952 жыл бұрын
bro nice work.
@smartswaggy61142 жыл бұрын
Cant you use simple methods like pop() and push()? Worst coding explanation ever
@prajwalurkude0072 жыл бұрын
Moron, he is coding in Java not C++.
@pironobcoding2 жыл бұрын
use your own brain, are you kid who need spoonfeeding of all the explanation, can't you see the efforts provided by the creators