The root of a binary tree and a value of a node (k) is given. The goal is to find distance of the closest leaf from that node.
For example if the tree is something like this:
7
/ \
5 6
/ \
2 3
/ \ / \
9 11 8 14
/ / \ \ \
10 12 15 16 18if k=5 then answer will be 2 (node 6 is at distance 2 from node 5).
I'm stuck. Please help me how to approach it.