Design a Stack that supports getMin() in O(1) time and O(1) extra space | Babbar DSA Sheet | Amazon🔥

Sdílet
Vložit
  • čas přidán 22. 07. 2021
  • #stacks #queues #stackqueue #competitiveprogramming #coding #dsa
    Hey, Guys in this video I have explained how we can solve the problem 'Design a Stack that supports getMin() in O(1) time and O(1) extra space'.
    Join our Telegram Channel for more Information
    🔰 Telegram Channel Link = t.me/CodeLibrary1
    🔰 Telegram Discussion Group Link = t.me/CodeLibraryDiscussion
    --------------------------------------------------------------------------------
    Unacademy Links--
    Use my code "YOGESH" to access all FREE classes and get a 10% Discount on Paid Courses.
    Exclusive 5- Month Learning Track for College/ Off-Campus Placements: bit.ly/3B5Rczq
    6-Week Mastercourse on Advanced Programming Topics: bit.ly/3kmF1In
    (Java) Complete Course on Programming for Beginners: bit.ly/2UOBbgq
    OS, DBMS & Networking Mastercourse: bit.ly/3AYscKi
    --------------------------------------------------------------------------------
    🔰 Array Playlist = • Love Babbar DSA 450 Qu...
    🔰 String Playlist = • Love Babbar DSA 450 Qu...
    🔰 Searching and Sorting Playlist = • Love Babbar DSA 450 Qu...
    🔰 Binary Tree Playlist = • Love Babbar DSA 450 Qu...
    🔰 Linked List Playlist = • Love Babbar DSA 450 Qu...
    🔰 Graph Playlist = • Love Babbar DSA 450 Qu...
    🔰 Dynamic Programming Playlist = • Love Babbar DSA 450 Qu...
    🔰 Informative Videos = • Informative Videos
    🔰 Love Babbar DSA Sheet: drive.google.com/file/d/1FMdN...
    Follow us on Instagram:
    🔰 Shailesh Yogendra : / shaileshyogendra
    🔰 Yogesh Yogendra : / i_am_yogesh_here
    Follow us on LinkedIn:
    🔰 Yogesh Yogendra : / yogesh-yogendra-26bbb518a
    🔰 Shailesh Yogendra : / shailesh-yogendra-8b13...
    Hope you like it. Comment if you have any doubt
    LIKE | SHARE | SUBSCRIBE

Komentáře • 27

  • @priyarathore9266
    @priyarathore9266 Před 2 lety +4

    Waah bhai...Kahin samajh nahi aa rha tha...bss tera hi samajh aaya...
    Well done bro...Great Explanation

  • @sunny_23561
    @sunny_23561 Před rokem +1

    Thanks very nicely explained

  • @154poojadas7
    @154poojadas7 Před 2 lety

    Thank you! Very well Explained💯

  • @anantsingla8274
    @anantsingla8274 Před 2 lety

    Great video.Thanks for sharing.👍👍

  • @tanoybhowmick8715
    @tanoybhowmick8715 Před 2 lety

    Thanks for the explanation.

  • @ICSSachinSingh
    @ICSSachinSingh Před 2 lety

    quite good explanation......

  • @AvinashKumar-pb2op
    @AvinashKumar-pb2op Před rokem

    Nice Explanation🤩

  • @baz2839
    @baz2839 Před rokem +1

    good video loigc ,same but instead of 2x-m if its confusing : simple logic is whenever you find a minimum element then store into stack as *previousminimum element
    MY CODE FOR LEETOCDE IN C++:
    class MinStack {
    public:
    stackst;
    int mini=-1;
    MinStack() {

    }

    void push(int val) {
    if(st.size()==0)
    {
    st.push(to_string(val));
    mini=val;
    }
    else
    {
    if(val

  • @Asha0224
    @Asha0224 Před 2 lety

    Thank you sir!

  • @pushpendrasingh275
    @pushpendrasingh275 Před rokem

    Great explanation

  • @sumitverma5873
    @sumitverma5873 Před rokem

    thanks bhaiya for explaining 2x-(2x-m)part

  • @eti7570
    @eti7570 Před 2 lety +1

    good one

  • @shreyagrawal3806
    @shreyagrawal3806 Před rokem

    nice explaination

  • @swapnildhiman6585
    @swapnildhiman6585 Před 2 lety

    🔥❤️

  • @saunaknandi1814
    @saunaknandi1814 Před 2 lety +1

    Bhai ye encrypt karne ke piche ka thinking bhi bata dete toh jada achha hota.

  • @Vishalvijay99
    @Vishalvijay99 Před 2 lety

    Pop is wrong. Neither the function is returning the value.. nor the v should be returned value. we need to calculate the value to be returned. If the value is greater than min then we can return top of the stack as it is. If it is lesser than min, then we need to return min value before changing the min

  • @ANKITKUMAR-hg3wb
    @ANKITKUMAR-hg3wb Před 2 lety +1

    agar bhai sirf dsa karlo aur competetive na karo tab bhi company crack ho sakti hai kya?

    • @RajeevSingh-dg5ro
      @RajeevSingh-dg5ro Před 2 lety

      Vro cp karo ya mat karo, interview main jo pooche wo aana chahiye bas!

  • @satyamjaiswal1222
    @satyamjaiswal1222 Před 3 lety +1

    why we are using (2x-min) trick if interviewer will ask the reason behind it then what we will say about it. I want to know intuition behind the (2x-min). If you can explain this then It will be very helpful for me.

    • @CodeLibrary
      @CodeLibrary  Před 3 lety

      Yaa bro we are using this formula so that we can get the previous minimum available in Stack

    • @CodeLibrary
      @CodeLibrary  Před 3 lety +1

      Aur mai woh deduction karke dikhaya na ki wapis hame "m" kaise mil raha h...wahi samjha dena

    • @satyamjaiswal1222
      @satyamjaiswal1222 Před 3 lety

      @@CodeLibrary ok

    • @swapnildhiman6585
      @swapnildhiman6585 Před 2 lety +2

      bcz overall value humme x se km rkhni hai N you can use any value instead of 2, bss at time of calculating new_min during pop function you have to use that new value you used during the time of encryption.

    • @dhruvchawla5462
      @dhruvchawla5462 Před 2 lety

      @@CodeLibrary Bro what if we only push the value in stack if it is less than the previous minimum and if not we dont push it by checking at every iteration

  • @abhaybanerjee1074
    @abhaybanerjee1074 Před 3 lety +1

    Are you planning to join any better company than Accolite?