Doubt on leetcode problem

problem link=

solu=lass Solution {
public:
int ans = 0;

vector<int>postorder(TreeNode* root){
    
    if(root == NULL)
        return {-1, -1};
    
    int left = postorder(root->left)[1] + 1;
    int right = postorder(root->right)[0] + 1;
    
    ans = max({ans, left, right});
    return {left, right};
}

int longestZigZag(TreeNode* root) {
    
    postorder(root);
    return ans;
}

};

In this above solution can u plz tell me why is the root->left is taken at index 1 pos and the root->right is taken at index 0 position

hello @Somasree

here u have alredy taken left so ur next step should be right for zig zag path that is the reason why we are looing for right(index 1) here.

and index 0 here

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.