Tap here to switch tabs
Problem
Submissions

Problem: Maximum Nesting Depth of Two Valid Parentheses Strings

Try to solve the Maximum Nesting Depth of Two Valid Parentheses Strings problem.

Statement

A valid parentheses string is defined by the following rules:

  • It is the empty string "".

  • It can be written as the concatenation of two valid parentheses strings A and B.

  • It can be written as ( followed by a valid parentheses string A followed by ).

The nesting depth of a valid parentheses string is defined as follows:

  • The depth of "" is 00.

  • The depth of A concatenated with B is max⁡(extdepth(A),extdepth(B))\max( ext{depth}(A), ext{depth}(B)), where A and B are valid parentheses strings.

  • The depth of ( followed by A followed by ) is 1+extdepth(A)1 + ext{depth}(A), where A is a valid parentheses string.

Given a valid parentheses string seq, split its characters into two disjoint subsequences A and B such that both A and B are valid parentheses strings, and max⁡(extdepth(A),extdepth(B))\max( ext{depth}(A), ext{depth}(B)) is minimized.

Return an array answer of length seq.size where answer[i] = 0 if seq[i] is assigned to A, and answer[i] = 1 if seq[i] is assigned to B. If there are multiple valid solutions, any of them may be returned.

Constraints:

  • 1≤1 \leq seq.size ≤10000\leq 10000

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Nesting Depth of Two Valid Parentheses Strings

Try to solve the Maximum Nesting Depth of Two Valid Parentheses Strings problem.

Statement

A valid parentheses string is defined by the following rules:

  • It is the empty string "".

  • It can be written as the concatenation of two valid parentheses strings A and B.

  • It can be written as ( followed by a valid parentheses string A followed by ).

The nesting depth of a valid parentheses string is defined as follows:

  • The depth of "" is 00.

  • The depth of A concatenated with B is max⁡(extdepth(A),extdepth(B))\max( ext{depth}(A), ext{depth}(B)), where A and B are valid parentheses strings.

  • The depth of ( followed by A followed by ) is 1+extdepth(A)1 + ext{depth}(A), where A is a valid parentheses string.

Given a valid parentheses string seq, split its characters into two disjoint subsequences A and B such that both A and B are valid parentheses strings, and max⁡(extdepth(A),extdepth(B))\max( ext{depth}(A), ext{depth}(B)) is minimized.

Return an array answer of length seq.size where answer[i] = 0 if seq[i] is assigned to A, and answer[i] = 1 if seq[i] is assigned to B. If there are multiple valid solutions, any of them may be returned.

Constraints:

  • 1≤1 \leq seq.size ≤10000\leq 10000