Question: Distance of closest leaf from given node in Binary Tree 0 2 . Problem Statement A binary tree is represented by the following structure: class
Distance of closest leaf from given node in Binary Tree Problem Statement A binary tree is represented by the following structure: class Treetode: def initself data: self.data self.left data None self.right None Implement the following function: def ClosestLeaf tree k: The function accepts the root node of a binary tree 'tree' and an integer k as its arguments. Implement the function to find distance of closest leaf from node with data k and Note: Return if input tree is empty. Return O if node given is itself a leaf node Assumption: Only one node is present in tree with data k Sample input tree: k: Sample Output The custom input format for the above case: The first line represents k in the second line the first integer represents the height of the tree, and the rest of the integers represent the level order traversal of the given tree, in second line represents an empty node Instructions : This is a template based question, DO NOT write the "main" function. Your code is judged by an automated system, do not write any additional welcomegreeting messages. "Save and Test" only checks for basic test cases, more rigorous cases will be used to judge your code while scoring. Additional score will be given for writing optimized code both in terms of memory and execution time.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
