Skip to content

Latest commit

 

History

History
23 lines (18 loc) · 499 Bytes

File metadata and controls

23 lines (18 loc) · 499 Bytes

int steps=0;
    
    int find(Node* root)
    {
        if(!root)
            return 0;
            
        int l=find(root->left);
        int r=find(root->right);
        
        steps += abs(l) + abs(r);
        
        return (l+r+root->key -1);
    }
    int distributeCandy(Node* root)
    {
        find(root);
        return steps;
    }