Monotonic Stack Explained

Kacy Codes
Kacy Codes
8.5 هزار بار بازدید - 2 سال پیش - Making coding videos to improve.
Making coding videos to improve. Subscribe for more!

Email: [email protected]

Time Complexity is O(n) for finding all previous/next greater elements because each element in the array is only pushed to the stack 1 time, and each element is only popped at most once.

Timestamps
0:00 What is a monotonic stack?
0:21 monotonically increasing stack - example
1:37 monotonically decreasing stack - example
2:16 find previous greater and next greater elements - example
5:58 Code - find previous greater and next greater elements
8:27 Code - find next greater elements using Array.fill() and popping
10:59 Code - find next greater elements using array.length
12:10 Code - find previous greater and next greater elements in one loop
15:44 Outro
2 سال پیش در تاریخ 1400/12/01 منتشر شده است.
8,582 بـار بازدید شده
... بیشتر