Valid Parentheses
Updated
Problem statement
Given a string s containing only (, ), [, ], {, and }, determine whether its brackets are valid.
Every opening bracket must close with the same type, and pairs must be properly nested. A closing bracket must match the most recent unmatched opening bracket. Return a boolean.
For this exercise, assume an empty string is valid.
Function
isValidParentheses(s: String) → booleanExamples
Example 1
s = "([]{})"return = trueBoth inner pairs close before the surrounding parentheses.
Example 2
s = "([)]"return = falseThe closing parenthesis cannot close while the square bracket remains unmatched.
Example 3
s = "(()"return = falseOne opening parenthesis remains unmatched.
Constraints
- For this exercise, assume
0 <= s.length <= 10^5. - The input contains only the six listed bracket characters.
More Vanguard Online Assessment questions
- Two SumOA · Seen Sep 2026
- Are They PangramsOA · Seen Nov 2025
- Missing WordsOA · Seen Nov 2025
- Spam DetectionOA · Seen Nov 2025
- Binge WatchingOA · Seen Jan 2023
- Minimum Moves Around a Circular ArrayOA · Seen Aug 2022
- Maximum Occurring CharacterOA · Seen Mar 2022
- Picking TicketsOA · Seen Mar 2022
- Tool List: Two Smallest ValuesOA · Seen Nov 2021
- Group AnagramsOA · Seen Nov 2019
Similar questions at other companies
- Validate a Bracket SequenceInMobi · OAInMobi interview questions
- Valid ParenthesesBlackRock · OABlackRock interview questions
- Valid Bracket SequenceNVIDIA · OA · PHONE SCREENNVIDIA interview questions
- Get Final StringIBM · OAIBM interview questions
- Backspace String CompareGoldman Sachs · OAGoldman Sachs interview questions
- The PromHackerEarth · OA
- Compare Character Arrays with BackspacesOdoo · OAOdoo interview questions
- Eliminate SubstringJP Morgan Chase · OAJP Morgan Chase interview questions
- Balancing ParenthesesOracle · OAOracle interview questions
- Collapse Equal Adjacent PairsHudson River Trading · OAHudson River Trading interview questions