← All Topics
Stacks
— Simple English
76 lessons · Data Structures & Algorithms · Simple English · Beginner Friendly
🔒
Premium course.
The first 3 lessons are free — subscribe to unlock the rest (one plan unlocks every premium course).
View plans
01
Understanding the Problem: Why We Need LIFO Order
Free
Understanding the Problem: Why Order Matters Before learning a new data structure, it helps to first understand the prob…
02
The Stack: A LIFO Data Structure
Free
Meet the Stack Some problems only make sense when you handle the most recent item first. The last thing you put away is …
03
Key Properties of a Stack: Capacity, Size, and Top
Free
Key Properties of a Stack Once you understand what a stack is — a pile of items where you always add and remove from the…
04
Stack Operations: Push, Pop, Size, and Top
🔒
Stack Operations: Push, Pop, Size, and Top A stack is a simple but strict data store. Think of it like a pile of plates:…
05
How to Build a Stack Using an Array
🔒
How to Build a Stack Using an Array A stack is a simple way to store data where you can only add or remove items from on…
06
Building a Stack Class Using an Array
🔒
Building a Stack Class Using an Array A stack is a collection where you can only add or remove items from one end, calle…
07
Finding the Size of a Stack
🔒
Finding the Size of a Stack A stack is a way to store items where you only add and remove from one end, called the top. …
08
Checking if a Stack is Empty
🔒
Checking if a Stack is Empty Sometimes, before you do anything with a stack, you need to ask a simple question: "Is ther…
09
The `top` Operation: Looking at the Top Item of a Stack
🔒
Looking at the Top of a Stack A stack is like a pile of plates. You can only touch the plate on top. The top operation l…
10
Pushing an Item onto a Stack
🔒
Pushing an Item onto a Stack A stack is a way to store items where you only add and remove from one end, called the top.…
11
The Pop Operation: Removing the Top Item from a Stack
🔒
The Pop Operation: Removing the Top Item from a Stack A stack is like a pile of plates. You can only add a plate to the …
12
Designing a Stack Using an Array
🔒
Designing a Stack Using an Array A stack is one of the simplest and most useful data structures in programming. The easi…
13
Two Stacks Sharing One Array
🔒
Two Stacks Sharing One Array A stack is a simple way to store data where you add and remove items from one end only — li…
14
Building a Stack with a Linked List
🔒
Building a Stack with a Linked List A stack is a simple data structure. You can only do two things with it: push (add an…
15
Building a Stack with a Linked List Inside a Class
🔒
Building a Stack with a Linked List Inside a Class A stack is a collection where you only add and remove items from one …
16
Finding the Size of a Stack (Linked List Version)
🔒
Finding the Size of a Stack A stack often needs to answer one simple question: "How many items are inside me right now?"…
17
Checking if a Stack is Empty (Linked List Version)
🔒
Checking if a Stack is Empty When you work with a stack, you often need to ask one simple question first: "Is there anyt…
18
Accessing the Top of the Stack
🔒
Accessing the Top of the Stack A stack is like a pile of plates. You always add a new plate on top, and the plate you ca…
19
Pushing an Item onto a Stack (Linked List Version)
🔒
Pushing an Item onto a Stack (Linked List Version) A stack is like a pile of plates. You add a new plate on top, and you…
20
The Pop Operation: Removing the Top Item from a Stack
🔒
The Pop Operation: Removing the Top Item from a Stack A stack lets you add and remove items from only one end — the top.…
21
Designing a Stack Using a Linked List
🔒
What is a Stack? A stack is a simple way to store items where you can only add or remove from one end — the top. Think o…
22
Understanding the Infix Notation
🔒
Understanding the Infix Notation Computers were first invented to do math much faster than humans could by hand. But bef…
23
Postfix Notation: Writing the Operator After the Operands
🔒
Postfix Notation (Reverse Polish Notation) When you write math like 2 + 3, you put the + sign between the two numbers. T…
24
Prefix Notation (Polish Notation): Operator First
🔒
Prefix Notation: Putting the Operator First When we write math the normal way, we put the operator (like +, -, , /) betw…
25
Evaluating Postfix Expressions Using a Stack
🔒
Evaluating Postfix Expressions Using a Stack When we do math by hand, we write expressions like 5 + 2. The operator (the…
26
Evaluating a Postfix Expression Using a Stack
🔒
Evaluating a Postfix Expression When you write math the normal way, you put the operator between the two numbers. For ex…
27
Evaluating Prefix Expressions Using a Stack
🔒
Evaluating Prefix Expressions Using a Stack When we write math, we usually put the operator between the two numbers, lik…
28
Evaluating a Prefix Expression
🔒
Evaluating a Prefix Expression When you do math, you usually write the operator between two numbers, like 6 / 3 or 8 + 2…
29
Evaluating an Infix Expression
🔒
Evaluating an Infix Expression When you write a normal math expression like (1+2)(3/4), you are using something called i…
30
Converting Postfix to Prefix Using a Stack
🔒
Converting Postfix to Prefix Using a Stack When we write a math expression like A + B, the operator + sits between its t…
31
Converting a Postfix Expression to a Prefix Expression
🔒
Converting a Postfix Expression to a Prefix Expression When we write math like 7 + 3, the operator (+) sits between the …
32
Converting a Postfix Expression Back to Infix Using a Stack
🔒
Converting a Postfix Expression Back to Infix You have probably written math like 5 + 2 your whole life. The operator (t…
33
Converting a Postfix Expression to Infix
🔒
Converting a Postfix Expression to Infix When we write math, we usually put the operator between the two numbers, like 5…
34
Converting Prefix Notation to Postfix Notation Using a Stack
🔒
Converting Prefix to Postfix Using a Stack In an expression, we can write the operator in three different places. In pre…
35
Convert a Prefix Expression to a Postfix Expression
🔒
Convert Prefix to Postfix When we write math, we usually put the operator between the two numbers, like 7 - 8. This ever…
36
Converting a Prefix Expression to Infix Using a Stack
🔒
Converting a Prefix Expression to Infix Two ways to write the same math We usually write math with the operator sitting …
37
Converting a Prefix Expression to Infix
🔒
Converting a Prefix Expression to Infix When we write math, we usually put the operator between the two numbers, like 7 …
38
Converting Infix Expressions to Postfix Using a Stack
🔒
Converting Infix Expressions to Postfix Using a Stack When we write math, we put the operator between the two numbers, l…
39
Converting Infix Expressions to Postfix
🔒
Converting Infix Expressions to Postfix When we write math, we usually put the operator between the two numbers. For exa…
40
Converting Infix Expressions to Prefix Using a Stack
🔒
Converting Infix to Prefix When we write math like 5 2 + 6 / 3 + 3, the operator sits between its two numbers. This ever…
41
Converting an Infix Expression to Prefix Notation
🔒
Converting an Infix Expression to Prefix Notation When we write math, we usually put the operator (like +, -, , /) betwe…
42
The Reversal Pattern: Using a Stack to Reverse a Sequence
🔒
The Reversal Pattern: Using a Stack to Reverse a Sequence A quick reminder about how data is stored In simple data struc…
43
The Reversal Pattern: Reversing a String with a Stack
🔒
The Reversal Pattern Some problems share the same shape, even when they look different on the surface. Once you learn to…
44
Stack Inversion: Reversing a Stack
🔒
Stack Inversion: Reversing a Stack A stack is a simple way to store things, one on top of another — just like a pile of …
45
Reverse a String Using a Stack
🔒
Reverse a String Using a Stack Imagine you have a word like abcdefgh, and you want to flip it so the last letter comes f…
46
Reverse an Array Using a Stack
🔒
Reverse an Array Using a Stack In this lesson, we learn how to flip an array so that its elements come out in the opposi…
47
Reversing the Order of Words in a String
🔒
Reversing the Order of Words in a String Imagine you have a sentence made of several words. Your job is to flip the orde…
48
The Previous Closest Occurrence Pattern: Finding the Previous Greater Item with a Stack
🔒
The Problem Imagine you have a row of numbers. For each number, you want to find the previous greater item — the closest…
49
The Previous Closest Occurrence Pattern: Finding the Previous Greater Item with a Stack
🔒
The Previous Closest Occurrence Pattern Some problems ask you to look backwards in a list and answer a simple-sounding q…
50
Preceding Superior Element: Finding the First Bigger Number on the Left
🔒
Preceding Superior Element Imagine you are standing in a line of people, and you want to know: who is the first person t…
51
Preceding Inferior Element: Finding the First Smaller Number to the Left
🔒
Preceding Inferior Element This is a classic problem that helps you practice thinking about an array from left to right …
52
Preceding Superior Element in a Circular Array
🔒
Finding the First Bigger Number on the Left (Circular) Imagine you have a list of numbers. For each number, you want to …
53
Preceding Inferior Element in a Circular Array
🔒
Finding the Preceding Inferior Element in a Circular Array This lesson is about a common type of array problem. Don't wo…
54
The Next Closest Occurrence Pattern: Finding the Next Greater Element with a Stack
🔒
The Next Closest Occurrence Pattern Imagine you are standing in a line of people of different heights, and for each pers…
55
The Next Closest Occurrence Pattern (Next Greater / Smaller Element)
🔒
The Next Closest Occurrence Pattern Imagine you are standing in a line of people of different heights. You look to your …
56
Succeeding Superior Element: The First Bigger Number to the Right
🔒
What the problem is asking You are given two lists of numbers, called arr1 and arr2. Every number in arr2 also appears s…
57
Succeeding Inferior Element: Finding the Next Smaller Number to the Right
🔒
Succeeding Inferior Element This lesson is about a common kind of array problem: for a given number, we want to find the…
58
Next Greater Element in a Circular Array
🔒
Next Greater Element in a Circular Array Imagine you are standing in a line of people, and each person has a height. For…
59
Finding the Next Smaller Element in a Circular Array
🔒
Finding the Next Smaller Element in a Circular Array Imagine you are standing on a number and you want to find the first…
60
Finding the Next Bigger Value for Each Node in a Linked List
🔒
Succeeding Superior Nodes The setup Imagine a linked list: a chain of boxes (called nodes) where each box holds a number…
61
Trapping Rain Water: How Much Water Can the Bars Hold?
🔒
Trapping Rain Water Imagine a row of walls of different heights standing side by side, with no gaps between them. Each w…
62
Largest Rectangle in a Histogram
🔒
Largest Rectangle in a Histogram What is a histogram? A histogram is just a row of bars standing next to each other. Eac…
63
The Sequence Validation Pattern: Using a Stack to Check Start and End Events
🔒
The Sequence Validation Pattern Some problems give you a list of items that are connected in pairs. Each pair has a star…
64
Spotting and Solving Sequence Validation Problems (Valid Brackets)
🔒
Spotting and Solving Sequence Validation Problems Some problems give you a list of things that happen in order, and a se…
65
Valid Parentheses: Checking if Brackets are Balanced
🔒
Valid Parentheses: Checking if Brackets are Balanced Imagine you are writing some math or code, and you use brackets lik…
66
Minimum Edits to Make Parentheses Valid
🔒
Minimum Edits to Make Parentheses Valid Imagine you are typing some brackets and you make a few mistakes. Some brackets …
67
Detecting Redundant Parentheses in an Expression
🔒
Detecting Redundant Parentheses Parentheses in a math expression are like brackets that group things together. They tell…
68
Balanced Span: Finding the Longest Balanced Parentheses Substring
🔒
Balanced Span: The Longest Stretch of Matching Parentheses Imagine you have a line of opening brackets ( and closing bra…
69
The Linear Evaluation Pattern: Using a Stack to Process a Sequence with Triggers
🔒
What problem are we solving? Sometimes you are given a list of items, one after another, and you must process them from …
70
Identifying the Linear Evaluation Pattern (Simplify a Linux Path with a Stack)
🔒
Identifying the Linear Evaluation Pattern Earlier you learned a technique called linear evaluation. It is a way to solve…
71
Simplify a UNIX File Path (Canonical Path)
🔒
Cleaning Up a Messy File Path In UNIX-style systems (like Linux and macOS), every file and folder has an address called …
72
Bracketed Reversal: Flipping the Letters Inside Brackets
🔒
Bracketed Reversal Imagine you have a sentence written on paper, and someone draws square brackets around a few words. T…
73
String Expansion: Decoding a k-Encoded String
🔒
String Expansion: Decoding a k-Encoded String Sometimes we store text in a short, "packed" form to save space, and later…
74
Formula Parsing: Reading a Chemical Formula String
🔒
Formula Parsing: Counting Atoms in a Chemical Formula Imagine someone hands you a chemical formula written as text, like…
75
Design a Min Stack: Getting the Smallest Value Instantly
🔒
Design a Min Stack A stack is a simple way to store data where you only ever add or remove from the top. Think of a pile…
76
Design a Max Stack: Get the Maximum in O(1) Time
🔒
Design a Max Stack A stack is a simple data structure where you add and remove items from the same end, called the top. …