Your question is Binary Tree Search Function. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Nintendo eShop services represent one search index as a binary tree of nodes. Given the root and a target value, return the path to the nearest matching node.
A path is an array containing "L" and "R", where each entry indicates moving to the left or right child. If multiple nodes contain the target at the same minimum depth, return the lexicographically smallest path, treating "L" < "R". Return None when no node matches.
Implement search_binary_tree(tree, target).
tree is either None or a nested dictionary with keys value, left, and right.value and target are integers.None.None if the target is absent.Use an algorithm that finds the shallowest match and avoids storing a complete path for every queued node.
def search_binary_tree(tree, target):