Solution using pairs and queue


#1

`int f(TreeNode *A){
if(A==NULL) return 0;

return max(f(A->left)+1,f(A->right)+1);

}
vector<vector > Solution::levelOrder(TreeNode* A) {
int d=f(A);
vector<vector>t(d);
queue<pair<TreeNode *,int>> q;
q.push({A,0});int ctr=0;
while(!q.empty()){

    TreeNode* root = q.front().first;
    int l = q.front().second;
    q.pop();
    t[l].push_back(root->val);
    if(root->left!=NULL) q.push({root->left,l+1});
    if(root->right!=NULL) q.push({root->right,l+1}); ctr++;
}
return t;

}`