Tree top view tree challenges

how hash map work as a global variable in this recursion calling ? becz we are calling this function and it is void type it does not return any thing so how we are printing in main this hash map.

static void verticalOrderPrint(TreeNode root, Map<Integer, Integer> m, int d) {
if (root == null) {
return;
}
if (!m.containsKey(d)) {
m.put(d, root.data);
}
verticalOrderPrint(root.left, m, d - 1);
verticalOrderPrint(root.right, m, d + 1);
}

Hashmap works by reference so it seems like it is global

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.

This map must have been passed from the main. And since HashMaps are transferred over the function call stack by reference, therefore, the same Map that was declared in the main is what we perform all our operations upon(and not on the copy of it). So, we can easily access it in main.

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.