Distance between two nodes

Write codeMedium25 minMeta style

Your task

Given a general binary tree as a level-order array arr (null for missing) and two distinct-or-equal values a and b that are both present, return the number of edges on the shortest path between them. If a == b the distance is 0. Values are distinct across the tree. 1 <= node count <= 20000.

Examples

distance_between_nodes(arr: list[int], a: int, b: int) -> int
Example 1
Inputdistance_between_nodes([1, 2, 3, 4, 5, 6, 7], 4, 7)
Output4