Valid Parentheses
Updated
Problem statement
Given a string s containing only ()[]{}, determine whether its brackets are balanced. Every closing bracket must match the most recent unmatched opening bracket of the same type, and every opening bracket must be closed.
For this exercise, assume the empty string is valid. Return a boolean.
Function
validParentheses(s: String) → booleanExamples
Example 1
s = "([]){}"return = trueEach pair has the correct type, and the square brackets close before their enclosing parentheses.
Example 2
s = "([)]"return = falseThe first closing parenthesis encounters an unmatched opening square bracket, so the nesting is invalid.
Constraints
- For this exercise, assume
0 <= s.length <= 10^5. - Every character is one of
( ) [ ] { }.
More Qualys Onsite Interview questions
- Delete a Doubly Linked List Node at a PositionONSITE INTERVIEW · Seen Oct 2026
- Find the Entry of a Linked List CycleONSITE INTERVIEW · Seen Oct 2026
- Implement Binary SearchONSITE INTERVIEW · Seen Oct 2026
- Insert a Doubly Linked List Node at a PositionONSITE INTERVIEW · Seen Oct 2026
- Rotate an Array Right by K StepsONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Valid ParenthesesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Valid ParenthesesEPAM · ONSITE INTERVIEWEPAM interview questions
- Rich Text Parser Part 1 (Validate Tokens)Figma · PHONE SCREEN · ONSITE INTERVIEWFigma interview questions
- Valid ParenthesesAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Valid ParenthesesKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Valid ParenthesesSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Minimum Parenthesis Removals and Their IndicesDoorDash · ONSITE INTERVIEWDoorDash interview questions
- Valid ParenthesesBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Maximum Parenthesis Nesting DepthRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Valid ParenthesesZillow · PHONE SCREEN · ONSITE INTERVIEWZillow interview questions