FastPrepBalanced Brackets
Problems/Balanced Brackets

Balanced Brackets

Airbnb logoAirbnb● EasyINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Airbnb software engineer intern interview in the United States in September 2019. It was one of two coding questions across two video interviews held one after the other that came after an online coding challenge. The task was to check whether the brackets in a string are balanced.

The report gives only the name of the question. Here, the string holds only the three bracket types (), [] and {}, and each opening bracket must be closed by the same type in the right order. The limits and examples are our own.

Our version is about 90% the same as the reported question.

You are given a string s made only of the bracket characters '(', ')', '[', ']', '{' and '}'. Decide whether its brackets are balanced.

The string is balanced when all of these hold:

  • Every opening bracket is closed by a closing bracket of the same type: '(' by ')', '[' by ']', and '{' by '}'.
  • Brackets close in the right order: a closing bracket always closes the most recent opening bracket that is still open.
  • Every closing bracket has an opening bracket before it to close.

Return true if s is balanced, and false otherwise.

Function

isValid(s: String) → boolean

Examples

Example 1

s = "{[()]}()"return = true

The '(' at index 2 is closed right away by the ')' at index 3. Then ']' closes the '[' at index 1, and '}' closes the '{' at index 0. The last two characters form their own pair. Every bracket is closed by the same type in the right order, so the string is balanced.

Example 2

s = "[(])"return = false

When the ']' at index 2 arrives, the most recent bracket that is still open is the '(' at index 1. A ']' cannot close a '(', so the pairs cross and the string is not balanced, even though each opening bracket has a closing bracket of the same type later in the string.

Example 3

s = "(()"return = false

The ')' at index 2 closes the '(' at index 1. The '(' at index 0 is never closed, so the string is not balanced.

Constraints

  • 1 <= s.length <= 104
  • s contains only the characters '(', ')', '[', ']', '{' and '}'.

More Airbnb Phone Screen questions

  • Read Across Sound TracksPHONE SCREEN · Seen Nov 2026
  • Text JustificationPHONE SCREEN · Seen Nov 2026
  • Decode and Store StringsPHONE SCREEN · Seen Oct 2026
  • Print Sentences as TablePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Detonate Bombs with Chain ReactionsPHONE SCREEN · Seen Aug 2026
  • Smallest Common RegionPHONE SCREEN · Seen Aug 2026
  • Longest Chain BookingPHONE SCREEN · Seen Aug 2026
  • Nested List Iterator with RemovePHONE SCREEN · Seen Jul 2026
  • Parse Query StringPHONE SCREEN · Seen May 2026
  • Pacific Atlantic Water FlowPHONE SCREEN · Seen May 2023

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

Interview reports that mention this question

  • Airbnb Intern OA and Onsite Rounds: 16 Experiences (Part 5 of 7)

Airbnb interview experiences

  • Airbnb SWE OA: Four-Level Banking System: 1 Experience
  • Airbnb Campus and Full-Time SWE OA / Interviews: 9 Experiences
  • Airbnb Intern Phone Interviews: 21 Experiences (Part 7 of 7)
  • Airbnb Intern OA and Phone Screens: 17 Experiences (Part 6 of 7)
  • Airbnb Intern OA, Diplomacy Game: 19 Experiences (Part 4 of 7)
All Airbnb interview questionsSee Airbnb hiring insights
Saved
class Solution {
    public boolean isValid(String s) {
      // Write your code here.
    }
}
Checking account…