Interview Query

Check Matching Parentheses

0
Have you seen this question before?

One of the basic steps in parsing string inputs is to check whether the opening and closing characters or tags match, i.e., to check if each opened parenthesis is closed eventually.

Given a list of strings, write a string parser that verifies the integrity of the parenthesis used in the string. The parser should return a list of booleans stating whether that string’s integrity was verified.

Example:

Input:

list_of_strings = [
    'f(x) + g(x)', 
    'sin(exp(x)}', 
    '((())just some string)', 
    '(4,{(3,4):x**2)']

Output:

def string_parser(list_of_strings) -> [True, False, True, True]
Next question: Daily Active Users
.....
Python 3.9.6
Loading editor
Use Shift + Enter to run code