from collections import deque
from structures import build_tree

def min_depth(root):
    if root is None:
        return 0
    queue = deque([(root, 1)])
    while queue:
        node, depth = queue.popleft()
        if node.left is None and node.right is None:
            return depth
        for child in (node.left, node.right):
            if child is not None:
                queue.append((child, depth + 1))
