Next level explanation❤💙 Java: class KthLargest { private int k; private PriorityQueue pq; public KthLargest(int k, int[] nums) { this.k = k; this.pq = new PriorityQueue(); for(int num : nums) { pq.offer(num); } //remove the extra elements till kth element is on top while(pq.size() > k) { pq.poll(); } } public int add(int val) { pq.offer(val); while(pq.size() > k) { pq.poll(); } return pq.peek(); } }
@codestorywithMIK Жыл бұрын
Thanks a lot JJ. Support of you guys is enough for me ❤️
@JJ-tp2dd Жыл бұрын
@@codestorywithMIK ♥️💙♥️
@souravjoshi2293 Жыл бұрын
Thanks man
@souravjoshi2293 Жыл бұрын
5:09 - This is why I love this channel
@ssboy58624 ай бұрын
Bhaiya Sabse best tarike se explain karte ho ap
@saquibabbas1709 Жыл бұрын
Mik Sir You you have best clarity to derive problems, waiting for your videos everyday Ready to learn new #DpSeries
@codestorywithMIK Жыл бұрын
Thanks a lot Abbas ❤️❤️❤️
@DurgaShiva7574 Жыл бұрын
no ratta... logic is here.. thanks a ton MIK.
@codestorywithMIK Жыл бұрын
Thanks a lot Vishnu ❤️❤️
@sunnyvlogs__ Жыл бұрын
Bhaiya Mera yeh observation hai Heap ke ques. par:- 1. If we are given to find Kth largest element, toh Maxheap will give better soln which is nlogn but Minheap will give optimal ans in nlogk. And this is vice-versa for kth smallest elements Solve dono se kar saktey but Time complexity mein farak rahega. Agar kuch galat likhe toh correct kariyega.