Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Validate Balanced Parentheses String

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

Your question is Validate Balanced Parentheses 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 consisting of parentheses (, ), {, }, [, and ], write a function to determine if the input string is valid. An input string is valid if:

  1. Open brackets must be closed by the same type of brackets.
  2. Open brackets must be closed in the correct order.

Constraints

  • 0 <= s.length <= 10^4
  • s consists of parentheses only

Function Signature

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