Vertical order print

this is the question of vertical order print

i am not getting the answer in a perfect order. please check my code

class Solution {
public:
void traversal(TreeNode* root,int d,map<int,vector >&m)
{
if(root==nullptr)
{
return;
}
m[d].push_back(root->val);
traversal(root->left,d-1,m);
traversal(root->right,d+1,m);
}
vector<vector> verticalTraversal(TreeNode* root) {

    vector<vector<int> >ans;
    map<int,vector<int> >m;
    int d=0;
    vector<int> temp;
    traversal(root,d,m);
    for(auto p:m)
    {
        for(auto x:p.second)
        {
            temp.push_back(x);
        }
        ans.push_back(temp);
        temp.clear();
    }
    return ans;
    
}

hello @aditikandhway
please share ur code using cb ide

@aditikandhway
your code is correct, it is giving WA because of order issue.
they havent clearly mentioned the output order .
please refer this thread for output order-> link

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.