Valid Parentheses
Easy Stack & Queue AI round
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
Input: s = "{[]()}"
Output: true
The first { pairs with the last }, and the [ ] pair and the ( ) pair both lie inside it, side by side, without overlapping.
Example 2
Input: s = "[{}(])"
Output: false
Example 3
Input: s = "(()"
Output: false
Constraints
1 ≤ s.length ≤ 10⁵sholds only the characters( ) [ ] { }
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.
Your first AI round is free.
Watch the explanation
More Stack & Queue
- Daily TemperaturesAI round · Medium
- Decode StringAI round · Medium
- Largest Rectangle in HistogramHard
- Maximal RectangleHard
- Remove K DigitsMedium