K stacks in a single array | GeeksforGeeks

Find Complete Code at GeeksforGeeks Article: www.geeksforgeeks.org/efficie...
This video is contributed by Bharathi.
Please Like, Comment and Share the Video among your friends.
Install our Android App:
play.google.com/store/apps/de...
If you wish, translate into local language and help us reach millions of other geeks:
kzread.info_cs_p...
Follow us on Facebook:
/ gfgvideos
And Twitter:
/ gfgvideos
Also, Subscribe if you haven't already! :)

Пікірлер: 43

  • @prasad8814
    @prasad88143 жыл бұрын

    Understood after listening for 10 times approximately for two days

  • @nandinirm2234

    @nandinirm2234

    2 жыл бұрын

    Haha this is funny

  • @nero9985
    @nero99853 жыл бұрын

    I feel like I sort of understand the first method but besides memorizing it, Idk if I'd be able to explain it on an interview

  • @viditsharma3929
    @viditsharma39293 жыл бұрын

    i wish was smart enough to grab the concept in one go. thanks btw good explanation

  • @sagaralwani75
    @sagaralwani754 жыл бұрын

    A few minutes ago I was searching for it... Thank u

  • @ramchandran7564
    @ramchandran75644 жыл бұрын

    You made the difficult logic look so simple. Thank u so much ..

  • @nehamalvia
    @nehamalvia4 жыл бұрын

    I could not understand it looking at the code, it became easier to understand with the example. thanks!

  • @koyavasudhalakshmi2073
    @koyavasudhalakshmi20733 жыл бұрын

    Mam is there any solution possible without using constructors for method2 provided in the geeksforgeeks link mentioned

  • @verma_jay
    @verma_jay Жыл бұрын

    Thanks a lot Bharathi ma'am for this wonderful explanation.

  • @ankitgoyal8556
    @ankitgoyal85564 жыл бұрын

    Nicely Explained.Thank u

  • @MemesYTpage
    @MemesYTpage2 жыл бұрын

    after watching this in knowledge kaze its clear,,,mashaallah its good

  • @aayushshah8443
    @aayushshah84434 жыл бұрын

    Explained it very well

  • @vanshrana7807
    @vanshrana78079 ай бұрын

    Great explanation. Thanks a lot!!

  • @algoman6589
    @algoman65892 жыл бұрын

    best solution on youtube

  • @koyavasudhalakshmi2073
    @koyavasudhalakshmi20733 жыл бұрын

    Awesome explanation 👌 👌👌👌👌👌👌👌👌

  • @aditikaushik7350
    @aditikaushik73503 жыл бұрын

    very nice video! thanks!

  • @abhinavagrawal3028
    @abhinavagrawal30283 жыл бұрын

    Why GFG videos are so monotonous? Please don't explain problems like a computer !!!!!!

  • @swatigupta9920
    @swatigupta99203 жыл бұрын

    Canyou explain for multiple queue also please

  • @vipulgupta1453
    @vipulgupta14534 жыл бұрын

    Just perfect

  • @swaw11
    @swaw113 жыл бұрын

    Beautiful code!

  • @akashgourav1412
    @akashgourav14122 жыл бұрын

    Great Explanation

  • @prasad8814
    @prasad88143 жыл бұрын

    We may not get an idea to implement it directly without knowing it before.

  • @byteZorvin
    @byteZorvin2 жыл бұрын

    Thanks for this

  • @amerdelic8710
    @amerdelic87102 жыл бұрын

    I understood this, but I couldn't get over how simple solution was so I had to make sure. The way I did this was just to create an array with k stack objects in it. I couldn't see beyond this solution honestly. IMO, anything beyond this is needlessly complicated. kStacks = [new Stack(), new Stack(), new Stack()]; And there you go lol.

  • @Sameer.Trivedi

    @Sameer.Trivedi

    2 жыл бұрын

    Question asks about implentation of stacks i.e. with the underlying data structure as an array. Stacks need to be implemented inside array only. You are using stacks which kind of defeats the purpose.

  • @ShivamSingh-km9xo
    @ShivamSingh-km9xo3 жыл бұрын

    At least you should have taken stack no.2 also for push and pop, just wrapped up the video in only stack no.1 . Then it would have been more clearer. Not nicely explained. Going to look another time!!

  • @chetan8524
    @chetan85242 жыл бұрын

    I watched lots of videos but didn't understand until I found this vido

  • @pranavsingh7770
    @pranavsingh7770 Жыл бұрын

    though the animations help and are quite clear but video is too short. I had to watch it multiple times to gain clarity. would have been better if you did 3-4 push and 2-3 pops and explained.

  • @koyavasudhalakshmi2073
    @koyavasudhalakshmi20733 жыл бұрын

    Mam what is the time complexity for best case and worst case?

  • @jashanbansal2613

    @jashanbansal2613

    2 жыл бұрын

    Contant

  • @sarahabraham88
    @sarahabraham883 жыл бұрын

    "Implementing multiple queues with single array. " please explain this concept.

  • @anukoolsrivastava4235
    @anukoolsrivastava42352 жыл бұрын

    How about implementing it using a circular array, as per cracking the coding interview book. Could that be a solution here (as I could not understand that )?

  • @TusharRaghav
    @TusharRaghav2 жыл бұрын

    ➡ Setup: in this method the elements of a given stack would be sitting at any available space unlike being next to each other like other implementations that we have seen so far. To know the top element of a stack we will maintain a top array of size k which will tell us the location of the top element of the stacks. Also we will use a next array of size n that will serve 2 purpose, if ith cell is filled in our stack array then ith cell in this next array will tell us the location of the element that is below it in the stack i.e that was pushed before it. For cells that are empty it will tell us the next empty cell in case we are filling this one. Apart from these we will have variable named free that will tell us left most free cell in the array. Initially we initialize the top array with value -1 since all stacks are initially empty. The next array is initialized with value i+1 where i is th index of the cell, because if we are filling ith cell then initially (i+1)th cell will be empty and logically we must go there. Our free variable will have initial value as 0. ➡ Working Of Push: Now when we want to push a value in jth stack (say) then we will have to insert it in the place that free is pointing to. Now since this is the new top of the jth stack we need to update the top array as top[j] = free. Now the free cell is getting filled so we need to also change the free variable to next free cell that is given to us by the next array. Also we need to to update the next array since now it is filled now and need to tell us the previous element in the stack which is current top. ➡ Working Of Pop: to pop an item from the jth stack we need to use top[j] to get the index of the top most element of the jth stack since this is now the new empty cell we have to bring free here also current value of free must go in the next array as when this cell gets filled again later then next will give us next free cell which is current free cell (i.e before pop), current value of next will give us the new top of the jth stack.

  • @CHINMAYADEHURY
    @CHINMAYADEHURY3 жыл бұрын

    How are we supposed to come up with this solution within 30 minutes in an interview?

  • @amandeepnokhwal2977

    @amandeepnokhwal2977

    3 жыл бұрын

    @@unstoppable9668 tu toh unstoppable hai na lavde

  • @realme-pl3po
    @realme-pl3po4 жыл бұрын

    not very clearly explained

  • @prasad8814
    @prasad88143 жыл бұрын

    Difficult problem...

  • @Abhishekkumar-fi1dy
    @Abhishekkumar-fi1dy Жыл бұрын

    Dimaag ka dahi ho gya😂

  • @theunknown1333
    @theunknown13332 жыл бұрын

    it took me 6-7 times to understand this..... :/

  • @baolongnguyen6499
    @baolongnguyen64994 жыл бұрын

    is that HinLish??

  • @lasue7244

    @lasue7244

    4 жыл бұрын

    no

  • @AbdulWahab-ms6bn
    @AbdulWahab-ms6bn7 ай бұрын

    the 43 comment

  • @sudhanshuraina1729
    @sudhanshuraina17292 жыл бұрын

    2 minute video extra ban jayegi to kuch lut nhi jayega, wasnt very clear