Stack pattern
Valid Parentheses
Given a string of brackets containing the characters (), [], and {}, determine whether it is valid: every opening bracket must be closed by a matching bracket of the same type, and brackets must close in the correct order. Watch it run step by step, then write your own pseudocode and get it checked by AI.
- LeetCode 20
- Easy
- 2 approaches
Sign in with Google or GitHub and you land straight on this page. DSA comes with the all labs plan and every ChaiCode batch.
StackLeetCode 20
Easy
From the first idea to the best one
- 01 Brute force · delete adjacent pairs O(n²)O(n) space
- 02 Optimized · stack of open brackets O(n)O(n) space
What you will learn
- How to read Valid Parentheses and spot the stack pattern in it
- Brute force · delete adjacent pairs: O(n²) time, O(n) space
- Optimized · stack of open brackets: O(n) time, O(n) space
- The pseudocode for each approach, its line lit as the animation runs
- Practice: write your own pseudocode and get it checked
More Stack
See Valid Parentheses run, step by step
Sign in and this page opens on the animation, with all 8 Stack problems beside it.
DSA comes with the all labs plan and every ChaiCode batch.