FrontendX
Valid Parentheses Checker
medium
Blind solve
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
1
/**
2
* @param {string} arg1
3
* @return {boolean}
4
*/
5
function solve(arg1) {
6
// solve Valid Parentheses Checker problem here
7
return false;
8
}
Click to start editing · javascript
Valid Parentheses Checker
Given a string of brackets, return true if the brackets are closed in the correct order.