Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Validate Nested Brackets

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

Your question is Validate Nested Brackets. 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

Cox Automotive's Dealer.com services exchange payloads that may contain nested grouping markers. Implement a method that determines whether a string of brackets is properly nested and closed.

A string is valid when every opening bracket has the correct closing bracket, brackets close in last-in, first-out order, and no closing bracket appears without a matching opener. The supported bracket pairs are (), [], and {}. An empty string is valid.

Formal Specification

Implement is_valid_brackets(s), where s is a string containing only the six bracket characters. Return True if the brackets are properly nested, otherwise return False.

Constraints

  • 0 <= len(s) <= 10^4
  • s contains only the six bracket characters
  • Return either True or False

Function Signature

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