Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Validate Balanced Bracket String

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Validate Balanced Bracket String. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Given a string s, determine whether it contains a valid set of balanced brackets. The string may contain the characters (), {}, and [], and may also include non-bracket characters that should be ignored. Return True if every opening bracket is closed by the correct type in the correct order; otherwise return False.

Constraints

  • 0 <= len(s) <= 10^5
  • s may contain bracket and non-bracket characters
  • Only the bracket types (), [], and {} are considered for validation

Function Signature

def is_balanced_brackets(s):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output