Validate a Bracket Sequence
Updated
Problem statement
Given a string sequence containing only the bracket characters ()[]{}, return whether it is valid.
A valid sequence closes every opening bracket with the same bracket type, and closes brackets in the reverse order in which they were opened.
Function
isValid(sequence: String) → booleanExamples
Example 1
sequence = "([]{})"return = trueEvery closing bracket matches the most recent unmatched opening bracket.
Example 2
sequence = "([)]"return = falseThe closing parenthesis appears before the nested square bracket closes.
Constraints
0 <= sequence.length <= 100000.- Every character is one of
(,),[,],{, or}.
Source note: The source image is a source-neutral excerpt of the author-reported prompt.
Similar questions at other companies
- Valid ParenthesesByteDance · PHONE SCREENByteDance interview questions
- Valid ParenthesesCisco · PHONE SCREENCisco interview questions
- Stack Formula InterpreterTypeSafe AI · 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
- Valid ParenthesesPeopleStrong · PHONE SCREENPeopleStrong interview questions