Monotonic Stack Data Structure Explained

Поделиться
HTML-код
  • Опубликовано: 1 дек 2024

Комментарии • 76

  • @PrajaktaKarandikar-t3w
    @PrajaktaKarandikar-t3w Год назад +199

    Very well explained, would be easier to learn without the moving background.

  • @sibiranganath
    @sibiranganath 3 месяца назад +10

    It's a god level explanation of monotonic stack.
    A request from your rest subscriber: Don't have that running background in the tutorial it's irritating .

  • @PssGameplayER
    @PssGameplayER Год назад +8

    first time heard about Monotonic Stack, thanks for explaining it so properly

  • @biswajeetpadhi100
    @biswajeetpadhi100 Год назад +20

    the background of this video is greatly designed. its very easy to focus with this background in motion

    • @algo.monster
      @algo.monster  Год назад +16

      can't tell if it's positive or sarcasm haha but yeah glad you like it!

    • @biswajeetpadhi100
      @biswajeetpadhi100 Год назад +5

      @@algo.monster the background in motion acts as a boundary to the actual content, so I think it really works.

    • @szymonpiechutowski2340
      @szymonpiechutowski2340 Год назад +14

      I am a complete opposite to this idea, I feel like this 🤮 when I see it. It is not optimal for every 🧠

  • @sparrow2068
    @sparrow2068 7 дней назад

    phenomenal bro, u got a talent for this

  • @Brxndz_
    @Brxndz_ Месяц назад

    This helped me solve Next Greater element without looking at your code, thanks!

  • @KuaisArts
    @KuaisArts Год назад +4

    Wow! Thanks for walking through the example, it was very insightful

  • @yoDQ
    @yoDQ 11 месяцев назад +2

    Thank you for the monotonic stack explainer. It may be helpful to also show an image of the heights array above the image of the answer array to help visualize the relationship between the two better while popping and inserting.

  • @sandeepamarnath3295
    @sandeepamarnath3295 Год назад +5

    Great video thanks. Trying to understand how the monotonic stack approach would be of O(n) time. We traverse the array only once for sure, but what about the pop operations? For a few elements of array, we are popping out of stack multiple times until we find a stack element that is greater than the current element, so are we not counting this towards the time complexity? If length of stack is k, wouldn't the overall time be O(nk)? Thanks again!

    • @algo.monster
      @algo.monster  Год назад +9

      Every element in the array is processed exactly once. When an element is popped from the stack, it does not re-enter. Consequently, the maximum number of operations is 2n, accounting for each element being pushed and popped once.

  • @LunaOoze
    @LunaOoze 6 месяцев назад

    Perfect explanation, thank you !

  • @guinea_horn
    @guinea_horn Месяц назад

    Really good explanation. I'll agree with everyone else and say that the background is extremely distracting, and it actually makes the bitrate of the whole video go down, making the quality poor whether I select 144p or 1080p. I also feel like you didn't explain the algorithm before going through the problem with the heights of people. You started going through the example, but I didn't know precisely what it was you were doing or why you were making the decisions that you were making. I think it would be nice to have a plain explanation of the problem and how the algorithm solves it before going through the problem step by step.

  • @ignassablinskas9175
    @ignassablinskas9175 7 месяцев назад

    Very nice explanation, great job.

  • @sharwariphadnis1298
    @sharwariphadnis1298 Год назад

    Awesome video! Easy to understand

  • @nagendrabommireddi8437
    @nagendrabommireddi8437 10 месяцев назад

    wow very good explanation. thank you..

  • @AyaGamal2010
    @AyaGamal2010 3 месяца назад +1

    Great!

  • @helloguys9201
    @helloguys9201 Год назад

    Wonderful Explanation and PPT's

  • @11csepratikshaargulewar71
    @11csepratikshaargulewar71 Месяц назад

    I kindly request that you should make videos avoiding moving backgrounds, as they can be distracting while concentrating . By the way, great explanation!

  • @hardiksinghal1360
    @hardiksinghal1360 6 месяцев назад

    Awesome explaination

  • @dhruvsakariya3129
    @dhruvsakariya3129 Год назад +1

    you made it very easy by making visualizing approach. Thanks

  • @aleksandr_t
    @aleksandr_t Год назад

    Great video, thank you a lot!

  • @rahbanghani4097
    @rahbanghani4097 10 месяцев назад

    would you be kind enough to share what is the application that you are using for the walk through of the solution :) Thank you in advance.

  • @Spamuse-w3i
    @Spamuse-w3i 10 месяцев назад +3

    The background is too distracting

  • @alexsinx
    @alexsinx Год назад +1

    Why is the time complexity O(n) if we have two nested loops? shouldn't it be o(n*m) where n is the number of elements in the array and m is the number of elements in the stack?

    • @algo.monster
      @algo.monster  Год назад +1

      The code can be indeed deceiving. But remember each element enters or exits at most once. This is why monotonic stack is a efficient data structure.

  • @himanshigarg1431
    @himanshigarg1431 3 месяца назад

    Thank you so much

  • @literallyjustsomegirl
    @literallyjustsomegirl 11 месяцев назад

    So helpful 😭🖤

  • @MahmoudHassan-m2t
    @MahmoudHassan-m2t 2 месяца назад

    thanks

  • @Tough802Peter
    @Tough802Peter Год назад

    bro is god

  • @AINikunjGour
    @AINikunjGour Год назад

    You are Osm bro..

  • @Avighna
    @Avighna 11 месяцев назад

    Before learning this, I'd just use a segment tree for the first question xD.

  • @codemonkey007
    @codemonkey007 7 месяцев назад

    Why the solution iterative the array from right side to left side, is this order matter?

    • @TragicGFuel
      @TragicGFuel 4 месяца назад

      The order is a choice, you could have used a strictly increasing function instead

  • @googleit2490
    @googleit2490 Год назад +2

    New Topic Learned!!
    Sep'11, 2023 06:36 pm

  • @bluesteel1
    @bluesteel1 Год назад

    Nice

  • @parulgarg5362
    @parulgarg5362 Год назад

    Thanks for the video! Feedback on the moving background : VERY DISTURBING

  • @dimahodan232
    @dimahodan232 Год назад

    why brute force is O(n^2)? Each element doesn't start from the beginning of the array.
    Isn't it O(n*m) where m is i - k - 1? where k is the current element.

    • @algo.monster
      @algo.monster  Год назад

      k is not an input parameter. we have to express it in n. after dropping the content it's n^2

    • @douglas5260
      @douglas5260 Год назад +2

      its n-1 + n-2 +n-3 ... = n**2

    • @BurtPredrag
      @BurtPredrag Год назад

      @@douglas5260 its not multiplication it should be addition

    • @douglas5260
      @douglas5260 Год назад

      @@BurtPredrag Yeah, I've corrected it. Thanks!

  • @gmoney_swag1274
    @gmoney_swag1274 Месяц назад

    Couldn’t you also go from left to right? You could store the indexes in the stack and as soon as you add an element greater than the element at the top of the stack, you keep removing the top until it’s equal or greater to the new element, while updating their values (sorry for the bad explanation)

  • @kaszatus2
    @kaszatus2 11 месяцев назад +4

    Literally the worst sample, because not much of exploration... Maybe thats why for you its most confusing... As so its this video...

  • @tauicsicsics
    @tauicsicsics 2 месяца назад

    great explanation but the moving background really makes me dizzy, could not watch it for more than 1 minute

  • @RahulBansal14
    @RahulBansal14 6 месяцев назад

    The moving background make it hard to follow.

  • @samueladdisu3729
    @samueladdisu3729 3 месяца назад +1

    The moving background is very distracting. I can't even watch the full video

  • @bogdan206
    @bogdan206 Год назад +2

    bro remove that background!

  • @tiger7858
    @tiger7858 Год назад +11

    very bad background

  • @ed2023bc
    @ed2023bc 9 дней назад

    Slow down, it's not a race. Unless you don't understand what you are doing.