Valid Parentheses
Updated
Problem statement
Given a nonempty string s containing only (, ), [, ], {, and }, determine whether it is valid.
A string is valid when:
- Every opening bracket is closed by the same type of bracket.
- Open brackets are closed in the correct order.
- Every closing bracket has a corresponding opening bracket of the same type.
Return true when s is valid; otherwise, return false.
Function
isValidParentheses(s: String) → booleanExamples
Example 1
s = "()"return = trueThe opening parenthesis is closed by the matching closing parenthesis.
Example 2
s = "()[]{}"return = trueEach opening bracket closes with the same type, and no bracket closes out of order.
Example 3
s = "([)]"return = falseThe closing parenthesis appears before the nested square bracket is closed.
Example 4
s = "([])"return = trueThe square brackets close first, followed by the surrounding parentheses.
Constraints
1 <= s.length <= 10^4.- Every character in
sis one of()[]{}.
More Meta Phone Screen questions
- Convert a Sorted Linked List to a Balanced BSTPHONE SCREEN · Seen Nov 2026
- Fuzzy Word Lookup With One Misspelled LetterPHONE SCREEN · Seen Nov 2026
- Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Run-Length Encoded Vector Dot ProductPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Time to Buy and Sell StockPHONE SCREEN · Seen Nov 2026
- First Element Greater Than KPHONE SCREEN · Seen Nov 2026
- Count Events in Rolling Minute WindowsPHONE SCREEN · Seen Oct 2026
- Valid Word AbbreviationPHONE SCREEN · Seen Oct 2026
- Shortest Path in a Binary MatrixPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Valid ParenthesesByteDance · PHONE SCREENByteDance interview questions
- Valid ParenthesesCisco · PHONE SCREENCisco interview questions
- Stack Formula InterpreterTypeSafe AI · PHONE SCREEN
- Validate a Bracket SequenceTripAdvisor · PHONE SCREEN
- Rich Text Parser Part 1 (Validate Tokens)Figma · PHONE SCREEN · ONSITE INTERVIEWFigma interview questions
- Valid ParenthesesOracle · PHONE SCREENOracle interview questions
- Valid ParenthesesAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Balanced Bracket String CheckRippling · PHONE SCREENRippling interview questions
- Valid Bracket SequenceNVIDIA · OA · PHONE SCREENNVIDIA interview questions
- Valid ParenthesesBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions