Are the Brackets Balanced
Updated
Problem statement
You are given a string s made of round (), square [] and curly {} brackets. Return true if the brackets are balanced, and false otherwise.
The brackets are balanced when every opening bracket is later closed by a closing bracket of the same kind, every closing bracket closes an earlier opening bracket, and pairs do not cross: a bracket opened later must be closed earlier. For example, [{}()] is balanced, while {[}] is not.
Function
isBalanced(s: String) → booleanExamples
Example 1
s = "[{()}]()"return = trueEach opening bracket is closed by the matching kind in the right order: ( closes first, then {, then [, and the last pair () stands on its own. The answer is true.
Example 2
s = "{(})"return = falseThe counts are fine (one of each kind opened and closed), but } arrives while ( is still the most recently opened bracket. Brackets may not cross, so the answer is false.
Example 3
s = "))(("return = falseThe string starts with a closing bracket that has nothing to close. The answer is false.
Constraints
1 <= s.length <= 10^4scontains only the characters(,),[,],{and}
More Adobe Phone Screen questions
- Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
- All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
- Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
- Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
- Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
- Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 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