Space and time complexity?

what will be the space and time complexity of right view code?

hello @namangarg31

time complexity -> O(n) because we r traversing the complete tree

space complexity -> O(h) where h is the height of the tree.