Valid Parentheses
Easy Stack & Queue
s is a string of brackets: each character is one of the opening brackets ([{ or the closing brackets )]}.
s is balanced when all of its brackets can be split into pairs, each an opening bracket and a later closing bracket of the same kind, so that any two pairs either nest, one lying wholly between the other's two brackets, or do not overlap at all.
Return true if s is balanced, and false if it is not.
Example 1
The first { pairs with the last }, and the [ ] pair and the ( ) pair both lie inside it, side by side, without overlapping.
Example 2
Example 3
Constraints
1 ≤ s.length ≤ 10⁵sholds only the characters( ) [ ] { }
Solve it here
Write it in Python, Java or C++, run it on your own cases, and submit against hidden tests.
Practice this in an AI round
30 minutes on this problem with an AI agent beside your code, then a report on your solution and how you used the agent.
See the AI roundWatch the explanation
More Stack & Queue
- Daily TemperaturesAI round · Medium
- Decode StringAI round · Medium
- Asteroid CollisionAI round · Medium
- Largest Rectangle in HistogramHard
- Maximal RectangleHard