Valid Parentheses
Updated
Problem statement
Given a string s containing only parentheses, square brackets, and braces, return whether it is valid.
- Every opening bracket must be closed by the same kind of bracket.
- Brackets must close in the reverse order in which they open.
- Every closing bracket must have a matching opening bracket.
The empty string is valid.
Function
isValid(s: String) → booleanExamples
Example 1
s = "([]){}"return = trueThe square brackets close inside the parentheses. The final pair of braces is also matched, so every bracket closes in the required order.
Example 2
s = "([)]"return = falseThe closing parenthesis arrives while the most recent opening bracket is a square bracket. These kinds do not match.
Constraints
- 0 <= s.length <= 10^4.
- Every character of s is one of (, ), [, ], {, or }.
More Expedia Onsite Interview questions
- Scramble StringONSITE INTERVIEW · Seen Sep 2026
- Smallest Sufficient TeamONSITE INTERVIEW · Seen Sep 2026
- Check Anagram Pairs Index by IndexONSITE INTERVIEW · Seen Oct 2025
- Fresh Oranges Left After Rotting StopsONSITE INTERVIEW · Seen Oct 2025
- Longest Increasing SubsequenceONSITE INTERVIEW · Seen Oct 2025
- Lowest Common Ancestor with Repeated and Missing ValuesONSITE INTERVIEW · Seen Oct 2025
- Shortest Substring with Exactly K OnesONSITE INTERVIEW · Seen Oct 2025
- Middle Element of a Linked ListONSITE INTERVIEW · Seen Nov 2024
- Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
- Mirror Image Binary TreesONSITE INTERVIEW · Seen Sep 2024
Similar questions at other companies
- Valid ParenthesesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Valid ParenthesesEPAM · ONSITE INTERVIEWEPAM interview questions
- Valid ParenthesesQualys · ONSITE INTERVIEWQualys interview questions
- Validate a Bracket SequenceInMobi · OAInMobi interview questions
- Rich Text Parser Part 1 (Validate Tokens)Figma · PHONE SCREEN · ONSITE INTERVIEWFigma interview questions
- Valid ParenthesesBlackRock · OABlackRock interview questions
- Valid ParenthesesAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Valid ParenthesesKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Valid ParenthesesVanguard · OAVanguard interview questions
- Valid ParenthesesSalesforce · ONSITE INTERVIEWSalesforce interview questions