Перейти к содержимому

Monotonic Stack Explained

Kacy Codes

0:00 / 0:00

Monotonic Stack Explained

11 281 просмотр · 4 года назад
Kacy Codes
1,29 тыс. подписчиков
11 281 просмотр · 4 года назад
Making coding videos to improve. Subscribe for more! Email: kacycodes@gmail.com 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