# Stack

> LIFO, parsing, monotonic stack.

Canonical: https://learn.significanthobbies.com/curriculum/concepts/stack

LIFO, parsing, monotonic stack.

- Difficulty: intro
- Tracks: DSA & Implementation

## Mental model

A stack is last-in-first-out: the last thing you pushed is the first thing you pop. Reach for one when the natural question is "what was the most recent unfinished thing?" — parsing, recursion, undo, matching brackets.



## Primary sources

- [Stack (Wikipedia)](https://en.wikipedia.org/wiki/Stack_(abstract_data_type)) (doc)

## Practice

### Valid parentheses with a stack

Implement isValid(s) for brackets ()[]{} using a stack.

**Expected evidence:** isValid("()[]{}") true; isValid("(]") false.

### Valid Parentheses

LeetCode #20 — Valid Parentheses. Solve on LeetCode, then implement here if you want it in your drill queue. https://leetcode.com/problems/valid-parentheses/

**Expected evidence:** Pass all LeetCode test cases for this problem.

### Daily Temperatures

LeetCode #739 — Daily Temperatures. Solve on LeetCode, then implement here if you want it in your drill queue. https://leetcode.com/problems/daily-temperatures/

**Expected evidence:** Pass all LeetCode test cases for this problem.

### Car Fleet

LeetCode #883 — Car Fleet. Solve on LeetCode, then implement here if you want it in your drill queue. https://leetcode.com/problems/car-fleet/

**Expected evidence:** Pass all LeetCode test cases for this problem.

## Review prompts

- In a monotonic stack, what does the stack hold at any moment, and what does a pop mean?


## Prerequisites

- [Arrays & Hashing](https://learn.significanthobbies.com/curriculum/concepts/array-hashing)

## Related concepts

- None assigned.

## Learning paths

- [DSA Practice](https://learn.significanthobbies.com/curriculum/roadmaps/dsa-practice)
