Maximum Nesting Depth of Two Valid Parentheses Strings

Problem Id: 1111 Difficulty: Medium


Intuition

Solution


class Solution:
    def maxDepthAfterSplit(self, seq: str) -> List[int]:
        ans = [0] * len(seq)
        depth = 0
        for i in range(len(seq)):
            if seq[i] == '(':
                depth += 1
                ans[i] = depth
            elif seq[i] == ')':
                ans[i] = depth
                depth -= 1
        return [i % 2 for i in ans]