Lowest Common Ancestor of a Binary Tree (LeetCode 236)
Asked in the Round 1 DSA stage. Given a binary tree with unique integer values and two existing node values p and q, return the value of their lowest common ancestor.
The tree is represented by nested dictionaries: {"val": number, "left": node_or_null, "right": node_or_null}. Implement lowest_common_ancestor(root, p, q).
def lowest_common_ancestor(root, p, q):