Given an N-ary tree. The task is to replace the values of each node with the sum of all its subtrees and the node itself. … Read More

# Tag Archives: n-ary-tree

Given an N-ary tree root, the task is to find the count of nodes such that their subtree is a binary tree. Example: Input: Tree… Read More

Given a generic tree such that each node has a value associated with it, the task is to find the largest number of connected nodes… Read More

Given an N-ary tree root, the task is to find the number of non-leaf nodes in the tree such that all the leaf nodes in… Read More

Given an N-ary tree root, the task is to check if it is symmetric horizontally (Mirror image of itself). Example: Input: root = … Read More

Given an N-ary tree root and a list of K nodes, the task is to find the number of common ancestors of the given K… Read More

Given a Generic Tree consisting of N nodes valued from 0 to (N – 1) where P[i]th in the array P[] denotes ith nodes parent(1-based… Read More

Given a tree consisting of N nodes an array edges[][3] of size N – 1 such that for each {X, Y, W} in edges[] there… Read More

Given a Generic Tree consisting of N nodes, the task is to find the ZigZag Level Order Traversal of the given tree. Examples: Input: Output:13… Read More

Given a N ary Tree consisting of N nodes, the task is to find the minimum distance from node A to node B of the… Read More

Given a generic tree consisting of N nodes and (N – 1) edges and an array of queries query[] of size Q consisting of the… Read More

Given a generic tree consisting of N nodes, the task is to find the maximum sum of the path from the root to the leaf… Read More

Given an N-ary Tree consisting of N nodes valued from [0, N – 1] and two binary arrays initial[] and final[] of size N such… Read More

Given an N-array Tree (Generic Tree) and an integer K, the task is to find the Kth smallest element in an N-array Tree. Examples: Input:… Read More

Given an N-array Tree consisting of N nodes and an integer K, the task is to find the Kth largest element in the given N-ary… Read More