Larry Explains.. Monoqueues Part 2

preview_player
Показать описание
Larry goes over monoqueue/min-queue, a data structure that's recently popular, explaining where and how it can be used, particularly in competitive programming.

#leetcode #coding #python #programming
Рекомендации по теме
Комментарии
Автор

Best monotonic queue explanation. Thank you so much.

jaideepkukkadapu
Автор

Send to your enemy was very very funny he he heeee. The explanation was great !

srivaishnav
Автор

Really appreciate your explanation on monotonic queue! It made much more sense than the LeetCode discussion code.

NkwAxhXLaegHZfcVTF
Автор

hey larry, I'm confused with for the O(nlogn) solution, how the dequeue methods ensure the min element remains in the queue, unless it was at the head of the queue ie: self.queue[0][0]. For example, if we have the queue [5, 6, 1, 10], a minheap for this queue, then if we call dequeue previous index would be 0 since we haven't popped anything from the queue yet. But since 0 is the smallest index in the queue, wouldn't while previousIndex<=self.pq[0][1] never break then we would run into a key error since there would be no more elements in self.pg?

hakankanplay
Автор

Useful video, Larry! Seen you in leetcode contests.

How to use/apply monotonic queues has been hard. Is there any academic literature/textbook that covers it? Couldn't find it using google.
Why is this data-struct not in books and not described or taught in university courses? Is it something only specific to competitive programming, if so, why?

Your video helps a bit in understanding it, but i'm really unsure why there is so dearth of resources to understand and, more importantly, APPLY monoqueue to programming problems.

Specifically: When we look at a problem, we know we need BST or heap if we need to find the search for a value quickly or find the min/max in constant time using heap, but how do we know exactly when to THINK about monoqueue?
what thought process to articulate to begin considering monotonic queues? once one knows or sees a solution use of monoqueue makes sense but that's hindsight 20/20. how to figure it out just by looking at a problem not solution?
how do we realize instantly looking at a problem to device a monoqueue that would solve it? particularly in interview conditions?

jmka
visit shbcf.ru