← All problems
StackEasy
Valid Parentheses
StackEasy
Step 1 of 8 · Understand
1. Understand the problem
Given a string made up of brackets — (, ), {, }, [, ] — determine whether all the brackets are correctly matched and properly nested.
Input
A string `s` containing only the characters `(`, `)`, `{`, `}`, `[`, `]`.
Output
A boolean — `true` if every opening bracket is closed by the correct type in the right order, `false` otherwise.
Examples
input → s = "()"
output → true
input → s = "()[]{}"
output → true
Three separate valid pairs, none nested.
input → s = "(]"
output → false
The open paren is closed by a bracket — wrong type.
input → s = "([)]"
output → false
The brackets are interleaved incorrectly — [ is closed before ( is closed.
Write your solution above and hit Run tests. Results and tips appear here.