FrontendX
Valid Parentheses Checker
medium
Description
AI Assistance
Solution
Test Cases
Test Result
Submissions
Canvas
Valid Parentheses
Checker
Given a string of brackets, return true if the brackets are closed in the correct order.
Examples
Example 1
Input:
"()"
Output:
true
Example 2
Input:
"(]"
Output:
false
Hints
Hint 1
Use a hash map to store the matching pairs of brackets for quick lookup.
Hint 2
When encountering a closing bracket, check if the stack is empty or if the top of the stack does not match the corresponding opening bracket.
Hint 3
Optimize space by using a counter instead of a stack for the case where only one type of bracket is present (e.g., "()").
Related Problems
two-sum
Valid Parentheses Checker
Given a string of brackets, return true if the brackets are closed in the correct order.