Problem Complete the function truncateTree() to take in a root node of a tree an
ID: 3719934 • Letter: P
Question
Problem
Complete the function truncateTree() to take in a root node of a tree and truncate the tree such that it has height n, which means that all nodes that fall on a level higher than n will be removed.
class Node:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
def truncateTree(root, n):
# TODO
Explanation / Answer
Hi. please find the answer above.. i have given comments so that it is very easy for you to understand the flow. In case of any doubts, please ask in comments. If the answer helps you, please upvote. Thanks!
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.