Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Balanced Brackets Validator

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

Your question is Balanced Brackets Validator. 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

Noblis software may receive compact configuration or message fragments containing parentheses and square brackets. Implement a method that determines whether every opening delimiter is closed by the correct delimiter in the correct order.

A string is valid when each ( has a matching ), each [ has a matching ], and delimiters are properly nested. Ignore all characters other than (, ), [, and ].

Formal Specification

Implement is_balanced(s), where s is a string. Return True if the relevant delimiters are balanced and properly nested; otherwise, return False. The empty string is considered valid.

Constraints

  • 0 <= len(s) <= 10^5
  • s contains printable characters
  • Only parentheses and square brackets affect validity
  • Return a boolean result

Function Signature

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