Skip to content

Stack

A stack is a pile of plates: you only touch the top one (last in, first out). It is the natural tool when the most recent unfinished thing must be dealt with first — nested brackets, undo, or "what is the next bigger value?".

After this topic: You can recognise "match the most recent thing" and "next greater element" problems and solve them in one pass.

Do these first: Arrays & Hashing

0 of 7 solved0%

Step 1 · Read the lesson

Stack Basics

Last in, first out: matching pairs, evaluating expressions, undo and a running minimum.

Step 2 · Solve the problems in order

Try each one for about 20 minutes first. Problems with a Run code tab are checked right here. If you are stuck, open Nudge, think again, then Idea. Go skeleton only gives the function shape, and Reference solution is for comparing after you have tried. Tick the box when you could solve it again without help.

  1. 2.Min Stack Medium
  2. 6.Car Fleet Medium