Skip to content

Practice Maximum Nesting Depth of Two Valid Parentheses Strings

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1111
LeetCode Problem

Maximum Nesting Depth of Two Valid Parentheses Strings

Problem Statement

A valid parentheses string is balanced: each closing parenthesis matches an earlier opening parenthesis, with none left unmatched. Its nesting depth is the maximum number of simultaneously open parentheses; the empty string has depth 0. Given the valid string seq, assign every character to one of two subsequences A and B, preserving order within each. Both subsequences must be valid. Minimize the larger of their nesting depths. Return an array with 0 for characters assigned to A and 1 for characters assigned to B. Any optimal assignment is accepted.

Source: Maximum Nesting Depth of Two Valid Parentheses Strings on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
seq = "(()())"
Output
[0,1,1,1,1,0]

# Example 2

Input
seq = "()(())()"
Output
[0,0,0,1,1,0,1,1]

Constraints

1 <= seq.size <= 10000

Related LeetCode Problems

Practice more problems similar to Maximum Nesting Depth of Two Valid Parentheses Strings.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.