Bottom view of binary tree

Write codeMedium25 minAmazon style

Your task

Given a binary tree as a level-order array arr (null for missing), return its bottom view: for each horizontal distance (root at 0, left child -1, right child +1), the value of the node that would be seen from directly below. When several nodes share a horizontal distance, the one visited LAST in a left-to-right level-order (BFS) traversal wins. Return values ordered by horizontal distance, left to right. 0 <= node count <= 10000.

Examples

bottom_view(arr: list[int]) -> list[int]
Example 1
Inputbottom_view([20, 8, 22, 5, 3, None, 25])
Output[5, 8, 3, 22, 25]