Stack of Plates ~ Cracking the Code (Python)

Hello everyone, today I am showing you a Stack question out of Cracking the Coding Interview. The question is 3.3 in the Stacks and Queues chapter. I discovered this implementation on-line and commented it for better understanding. The video below is also an explanation of the process.

The stack of plates question basically asks that, given a capacity, we stack plates up to that capacity. Once we’ve reached the capacity, we create a new stack and build up.

sop1

 

sop2

popat.png

My video is below, but if you still can not understand. I recommend you use PYTHON TUTOR . It is amazing. Just place the code in the visualizer with an argument and you’ll see every step.

One Comment Add yours

  1. Gaurav says:

    at the function popAt, shouldn’t the comparison(2nd if statement) have index rather than index – 1

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s