A string is a valid parentheses string&nbsp;(denoted VPS) if and only if it consists of "(" and ")" characters only, and:


	It is the empty string, or
	It can be written as&nbsp;AB&nbsp;(A&nbsp;concatenated with&nbsp;B), where&nbsp;A&nbsp;and&nbsp;B&nbsp;are VPS's, or
	It can be written as&nbsp;(A), where&nbsp;A&nbsp;is a VPS.


We can&nbsp;similarly define the nesting depth depth(S) of any VPS S as follows:


	depth("") = 0
	depth(A + B) = max(depth(A), depth(B)), where A and B are VPS's
	depth("(" + A + ")") = 1 + depth(A), where A is a VPS.


For example,&nbsp; "",&nbsp;"()()", and&nbsp;"()(()())"&nbsp;are VPS's (with nesting depths 0, 1, and 2), and ")(" and "(()" are not VPS's.

&nbsp;

Given a VPS seq, split it into two disjoint subsequences A and B, such that&nbsp;A and B are VPS's (and&nbsp;A.length + B.length = seq.length).

Now choose any such A and B such that&nbsp;max(depth(A), depth(B)) is the minimum possible value.

Return an answer array (of length seq.length) that encodes such a&nbsp;choice of A and B:&nbsp; answer[i] = 0 if seq[i] is part of A, else answer[i] = 1.&nbsp; Note that even though multiple answers may exist, you may return any of them.

&nbsp;
Example 1:

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


Example 2:

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


&nbsp;
Constraints:


	1 &lt;= seq.size &lt;= 10000


class Solution:
    def maxDepthAfterSplit(self, seq: str) -> List[int]:
        ans = []
        last = 1
        for i in seq:
            if i == '(':
                if last == 0: ans.append(1)
                else:ans.append(0)
            else:
                ans.append(last)
            last = (last + 1) % 2
        return ans
class Solution {
    public int[] maxDepthAfterSplit(String seq) {
        int[] res = new int[seq.length()];
        for(int i=0; i<seq.length(); i++){
            res[i] = seq.charAt(i) == '(' ? i & 1 : 1-i & 1; 
        }
        return res;
    }
}
    class Solution {
public:
    vector<int> maxDepthAfterSplit(string seq) {
        //since we want the difference to be as low as possible so we will try to balance both A and B by trying to maintain the number of paranthesis as close as close as possible
        vector<int> indexA, indexB, res(seq.length(), 0 );
		//initailly assuming all parenthesis belong to A so filling res with 0
        int i = 0;
        int addToA = 0, addToB = 0;
        while(i < seq.length()){
            if(seq[i] == '('){
                if(addToA <= addToB){
                    //adding depth to A when it's depth is lesser or equal to b
                    indexA.push_back(i);
                    addToA ++;
                }else{
                    indexB.push_back(i);
                    addToB++;
                }
            }else{
                // removing depth from string whose depth is maximum as we have to keep the difference minimum
                if(addToA >= addToB){
                    addToA--;
                    indexA.push_back(i);
                }else{
                    indexB.push_back(i);
                    addToB--;
                }
            }
           i++;
        }
         for(i = 0; i < indexB.size(); i++){
                res[indexB[i]] = 1;
            }
         return res;   
    }
};
/**
 * @param {string} seq
 * @return {number[]}
 */
var maxDepthAfterSplit = function(seq) {
    let arr = []
    for(let i=0; i<seq.length; i++){
        arr.push(seq[i] == "(" ? i & 1 : 1-i & 1)
    }
    return arr
};
Maximum Nesting Depth of Two Valid Parentheses Strings