Skip to main content

Stack Vis

Memory & Logic

Stack is empty

0/0
1x
Algorithm Details
Complexity Profile
TimeO(n)
SpaceO(n)
AverageO(n)

Uses a stack to keep track of opening brackets. Each character is pushed or popped exactly once.

Algorithm Logic
1Algorithm IsValid(s):
2 stack = Empty Stack
3 For each char in s:
4 If char is opening '(', '{', '[':
5 stack.push(char)
6 Else:
7 If stack is empty or mismatch:
8 Return False
9 stack.pop()
10 Return stack.isEmpty()