Lesson overview · Free interview practice

Stacks

Explore stack operations and their applications in computer science.

Topics in the full lesson
  • Concept and Use Cases
  • When to Use
  • Time and Space Complexity
  • Stack Operations and Methods
  • Practical Tips and Tricks
  • Common Gotchas
  • Advanced Topics
  • Stack Algorithms
  • Interview Tips and Tricks
  • Common Mistakes

Practice Problems

Work through a question before revealing its explanation. These questions and answers are free; Premium adds the full lesson walkthrough, examples and implementation detail.

Completion marks record your own progress, not an automatically checked result. The task type does not determine whether it is optional.

Question

Given a string s containing only the characters '(', ')', '{', '}', '[', ']', determine if the input string is valid: open brackets are closed by the same type of brackets, and open brackets are closed in the correct order. Solve using a stack.

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

Question

Given an array heights where heights[i] is the height of the i-th building in a row and the ocean lies to the right of the last building, a building has an ocean view if every building to its right is strictly shorter than it. Return the indices of all buildings with an ocean view, in increasing order.

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

Question

Given a string s of lowercase letters and the characters ( and ), remove the minimum number of parentheses (from any positions) so that the resulting string is valid — every ( has a matching ) and every ) has a matching (. Return any valid result string.

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

Question

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how many units of water can be trapped after raining.

Take a moment to think about this before revealing the answer

Explain your reasoning or try an implementation before comparing answers.

Explore the full Stacks material

Premium includes the complete lessons and implementation references. Free practice questions remain available without a subscription.

All course tracks & premium content
From basics to advanced masterclasses
Built for JS/TS developers like you
Real-world tips & common pitfalls
Upgrade to Premium