Monotonic Stack Data Structure Explained

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 ก.ย. 2024

ความคิดเห็น • 68

  • @PrajaktaKarandikar-t3w
    @PrajaktaKarandikar-t3w ปีที่แล้ว +169

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

    • @JackHou-vw7hs
      @JackHou-vw7hs ปีที่แล้ว +11

      I loved the moving background. It helped me stay focused

    • @bluesteel1
      @bluesteel1 11 หลายเดือนก่อน +28

      Everything was fine before i read your comment. Now i cant ignore it .

    • @jigar2238
      @jigar2238 11 หลายเดือนก่อน +3

      @@bluesteel1 😆

    • @siddhantprakash.
      @siddhantprakash. 8 หลายเดือนก่อน +2

      @@bluesteel1 😂

    • @adityapratapsinghtomer3624
      @adityapratapsinghtomer3624 หลายเดือนก่อน +1

      @@JackHou-vw7hs my man

  • @PssGameplayER
    @PssGameplayER ปีที่แล้ว +6

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

  • @KuaisArts
    @KuaisArts ปีที่แล้ว +4

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

  • @alexsinx
    @alexsinx 10 หลายเดือนก่อน +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  10 หลายเดือนก่อน +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.

  • @kaszatus2
    @kaszatus2 9 หลายเดือนก่อน +4

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

  • @sibiranganath
    @sibiranganath หลายเดือนก่อน +5

    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 .

  • @samueladdisu3729
    @samueladdisu3729 หลายเดือนก่อน +1

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

  • @sandeepamarnath3295
    @sandeepamarnath3295 10 หลายเดือนก่อน +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  10 หลายเดือนก่อน +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.

  • @Spamuse-w3i
    @Spamuse-w3i 8 หลายเดือนก่อน +2

    The background is too distracting

  • @bogdan206
    @bogdan206 10 หลายเดือนก่อน +2

    bro remove that background!

  • @tauicsicsics
    @tauicsicsics 17 วันที่ผ่านมา

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

  • @AyaGamal2010
    @AyaGamal2010 หลายเดือนก่อน +1

    Great!

  • @RahulBansal14
    @RahulBansal14 4 หลายเดือนก่อน

    The moving background make it hard to follow.

  • @yoDQ
    @yoDQ 8 หลายเดือนก่อน +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.

  • @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  ปีที่แล้ว +15

      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 ปีที่แล้ว +11

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

  • @MahmoudHassan-m2t
    @MahmoudHassan-m2t 9 วันที่ผ่านมา

    thanks

  • @Avighna
    @Avighna 9 หลายเดือนก่อน

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

  • @rahbanghani4097
    @rahbanghani4097 8 หลายเดือนก่อน

    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.

  • @himanshigarg1431
    @himanshigarg1431 หลายเดือนก่อน

    Thank you so much

    • @algo.monster
      @algo.monster  หลายเดือนก่อน

      You're most welcome

  • @googleit2490
    @googleit2490 ปีที่แล้ว +2

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

  • @parulgarg5362
    @parulgarg5362 11 หลายเดือนก่อน

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

    • @algo.monster
      @algo.monster  10 หลายเดือนก่อน

      Thanks and Noted!

  • @nagendrabommireddi8437
    @nagendrabommireddi8437 8 หลายเดือนก่อน

    wow very good explanation. thank you..

  • @codemonkey007
    @codemonkey007 5 หลายเดือนก่อน

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

    • @TragicGFuel
      @TragicGFuel 2 หลายเดือนก่อน

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

  • @hardiksinghal1360
    @hardiksinghal1360 3 หลายเดือนก่อน

    Awesome explaination

  • @PhuocOngGia
    @PhuocOngGia ปีที่แล้ว

    bro is god

  • @bluesteel1
    @bluesteel1 11 หลายเดือนก่อน

    Nice

  • @ignassablinskas9175
    @ignassablinskas9175 5 หลายเดือนก่อน

    Very nice explanation, great job.

  • @LunaOoze
    @LunaOoze 4 หลายเดือนก่อน

    Perfect explanation, thank you !

    • @algo.monster
      @algo.monster  3 หลายเดือนก่อน

      Glad it was helpful!

  • @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!

  • @tiger7858
    @tiger7858 ปีที่แล้ว +10

    very bad background

  • @sharwariphadnis1298
    @sharwariphadnis1298 ปีที่แล้ว

    Awesome video! Easy to understand

  • @helloguys9201
    @helloguys9201 ปีที่แล้ว

    Wonderful Explanation and PPT's

  • @literallyjustsomegirl
    @literallyjustsomegirl 9 หลายเดือนก่อน

    So helpful 😭🖤

    • @algo.monster
      @algo.monster  8 หลายเดือนก่อน

      Glad it helped!

  • @AINikunjGour
    @AINikunjGour ปีที่แล้ว

    You are Osm bro..

  • @aleksandr_t
    @aleksandr_t ปีที่แล้ว

    Great video, thank you a lot!

  • @dhruvsakariya3129
    @dhruvsakariya3129 ปีที่แล้ว +1

    you made it very easy by making visualizing approach. Thanks