Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Validate Balanced Parentheses String
00:00
5 left

Validate Balanced Parentheses String

EasyPython

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:
Interviewer

Your question is Validate Balanced Parentheses String. Start with the requirements in the Question tab.

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.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.