Distance between tree nodes

Write codeMedium30 min

Your task

Given a binary tree as a level-order list (None marks a missing child; children of None are omitted) and two values p and q that may or may not be present, return the number of edges on the path between the nodes with those values. All node values are distinct. If either value is absent, return -1. If p == q (and present), the distance is 0.

Examples

distance_between_nodes(level: list, p: int, q: int) -> int
Example 1
Inputdistance_between_nodes([3, 5, 1, 6, 2, 0, 8, None, None, 7, 4], 5, 0)
Output3