Balanced Bracket String Check
Updated
Problem statement
You are given a string s made of three kinds of brackets: round ( ), square [ ] and curly { }.
The string is balanced when every opening bracket is closed by a closing bracket of the same kind, every closing bracket closes an earlier opening bracket, and brackets close in the reverse order they were opened, so pairs never cross. For example, [{}] is balanced but [{]} is not.
Return true if s is balanced, and false otherwise.
Function
isValid(s: String) → booleanExamples
Example 1
s = "{[()()]}"return = trueEach closing bracket closes the most recently opened bracket that is still open, and that bracket is always the same kind. Nothing is left open at the end, so the answer is true.
Example 2
s = "[(])"return = falsePositions count from 0. The ] at position 2 arrives while the ( at position 1 is the most recently opened bracket that is still open, so the brackets cross. The answer is false, even though each kind has one opening and one closing bracket.
Example 3
s = "({}[]"return = falseThe pairs {} and [] close, but the first ( is never closed. The answer is false.
Constraints
1 <= s.length <= 10^4sconsists only of the characters(,),[,],{and}.
More Rippling Phone Screen questions
- Filter, Sort, and Deduplicate Scheduled TasksPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Stateful Log Transform and SearchPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Dependency-Aware Task SchedulerPHONE SCREEN · Seen Nov 2026
- Delivery Cost Tracker with Effective-Dated RatesPHONE SCREEN · Seen Nov 2026
- Camel CardsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best and Worst Camel Card CompletionsPHONE SCREEN · Seen Nov 2026
- Corporate Card Expense RulesOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- In-Memory Priority Task SchedulerPHONE SCREEN · Seen Oct 2026
- Limit an Organization Tree's HeightPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Median Across N Sorted ArraysPHONE SCREEN · Seen Oct 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
- Valid Bracket SequenceNVIDIA · OA · PHONE SCREENNVIDIA interview questions
- Valid ParenthesesBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Valid ParenthesesPeopleStrong · PHONE SCREENPeopleStrong interview questions