P2 · 1 second · 256 MB
Valid Parentheses
Given a string `s` containing only `'('`, `')'`, `'{'`, `'}'`, `'['`, and `']'`, return true if it is valid. Open brackets must close in the correct order and with the matching type.
function isValid(s) → boolean
CONSTRAINTS
- 1 ≤ s.length ≤ 10⁴
- s contains only the six bracket characters
Input: s = "()"
Output: true
Input: s = "()[]{}"
Output: true
Input: s = "(]"
Output: false
1
2
3
4
5
6
7
8
Arena judges JavaScript in a Web Worker (1s wall-clock, then TLE). Samples are public; submit runs hidden tests too. C++/Python is a later swarm package.