Valid Parentheses
Easy · Stack & Strings · String · Stack
Problem
Given a string s containing only the characters ()[]{}, decide whether the brackets are balanced.
A string is valid when every opening bracket is closed by the same type of bracket, and brackets close in the right order — so ([)] is invalid even though the counts match.
Examples
Input: s = "()[]{}"
Output: TrueInput: s = "([)]" Output: False
Correct counts, wrong nesting order.
Input: s = "{[]}"
Output: TrueProperly nested.
Constraints
- 1 <= len(s) <= 10^4
- s consists of the characters ()[]{} only
Approaches
- Repeatedly delete adjacent pairs — time O(n²), space O(n)
Related problems
Start free on Cariara · Coding problems · System design studio