#1111
Maximum Nesting Depth of Two Valid Parentheses Strings
specialist · 605 · lc medium +29 · failed · 71.9% accepted · 468 likes · top 81%
Description
A valid parentheses string (VPS) is empty, AB where A and B are VPS's, or (A) where A is a VPS. The nesting depth is defined as: depth("") = 0, depth(A+B) = max(depth(A), depth(B)), depth("("+A+")") = 1 + depth(A).
Given a VPS seq, split it into two disjoint subsequences A and B (both VPS's) minimizing max(depth(A), depth(B)).
Return an array where answer[i] = 0 if seq[i] belongs to A, or 1 if it belongs to B.
Example 1:
Input: seq = "(()())"
Output: [0,1,1,1,1,0]
Example 2:
Input: seq = "()(())()"
Output: [0,0,0,1,1,0,1,1]
Code
1
2
3