LeetCode solutions

1208. Maximum Nesting Depth of Two Valid Parentheses Strings

My accepted Python solution to LeetCode problem 1208, Maximum Nesting Depth of Two Valid Parentheses Strings, running in 3ms.

  • Difficulty: Medium
  • Python
  • Runtime 3ms
  • Memory 17.4MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 3ms, memory 17.4MB, accepted 2026-01-02.

python
class Solution:
    def maxDepthAfterSplit(self, seq: str) -> List[int]:
        # Assign parentheses at odd depth to A, even depth to B
        result = []
        depth = 0
        
        for c in seq:
            if c == '(':
                depth += 1
                result.append(depth % 2)
            else:
                result.append(depth % 2)
                depth -= 1
        
        return result

Source