Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Parenthesis Validity Check

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

Your question is Parenthesis Validity Check. 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

Incedo configuration content may contain nested grouping symbols that must be balanced before it is processed. Given a string, determine whether every (), [], and {} delimiter is correctly opened, nested, and closed.

Non-delimiter characters such as letters, digits, spaces, and operators must be ignored. A closing delimiter is valid only when it matches the most recently opened delimiter. Return True when the complete string is valid, otherwise return False.

Formal Specification

Implement is_valid_parentheses(s), where s is a string. Return a Boolean:

  • True if all delimiters are balanced and correctly nested.
  • False if a delimiter is unmatched, incorrectly ordered, or left open.

An empty string or a string containing no delimiters is valid.

Constraints

  • 0 <= len(s) <= 10^5
  • s contains printable ASCII characters
  • Only (), [], and {} are treated as delimiters
  • Non-delimiter characters must be ignored

Function Signature

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