Valid Parentheses
Updated
Problem statement
Return whether a string of brackets is balanced. Each closing bracket must match the type of the most recent unmatched opening bracket, and every opening bracket must eventually close.
The supported bracket types are (), [] and {}. The empty string is balanced.
Function
isValid(s: String) → booleanExamples
Example 1
s = "{[()]}"return = trueEach close matches the most recent opening, so the complete string is balanced.
Example 2
s = "(]"return = falseThe closing square bracket does not match the opening parenthesis.
Constraints
0 <= s.length <= 4000scontains only()[]{}.
More BAMTECH Media Phone Screen questions
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