2
* Definition for a binary tree node.7
* TreeNode() : val(0), left(nullptr), right(nullptr) {}8
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}9
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left),15
// hd - horizontal distance16
// vertical order traversal starts from least hd to highest hd17
// on moving left hd decreases by 1, on moving right it increases by 119
// should do level order traversal to get the nodes with same hd in correct22
vector<vector<int>> verticalTraversal(TreeNode *root) {23
map<int, vector<int>> mp;24
queue<pair<TreeNode *, int>> q;28
map<int, multiset<int>> temp;29
for (int i = 0; i < sz; i++) {32
temp[pr.second].insert(pr.first->val);33
if (pr.first->left != NULL) {34
q.push({pr.first->left, pr.second - 1});36
if (pr.first->right != NULL) {37
q.push({pr.first->right, pr.second + 1});40
for (auto pr : temp) {41
for (auto val : pr.second) {42
mp[pr.first].push_back(val);46
vector<vector<int>> ans;49
for (auto val : pr.second) {