Given a tree, and the weights (in the form of strings) of all the nodes, the task is to count the nodes whose weighted string when concatenated with the strings of the sub-tree nodes becomes a pangram.
Pangram: A pangram is a sentence containing every letter of the English Alphabet.
Only the weighted string of sub-tree of node 1 makes the pangram.
Approach: Perform dfs on the tree and update the weight of every node such that it stores its weight concatenated with the weights of the sub-tree nodes. Then, count the nodes whose updated weighted string forms a pangram.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Subtree of all nodes in a tree using DFS
- Count of all prime weight nodes between given nodes in the given Tree
- Number of leaf nodes in the subtree of every node of an n-ary tree
- Count of nodes having odd divisors in the given subtree for Q queries
- Convert a Binary Tree such that every node stores the sum of all nodes in its right subtree
- Change a Binary Tree so that every node stores sum of all nodes in left subtree
- Common nodes in the inorder sequence of a tree between given two nodes in O(1) space
- Count the nodes in the given tree whose weight is even
- Count the nodes in the given tree whose weight is even parity
- Count the number of nodes at a given level in a tree using DFS
- Count the nodes of the given tree whose weight has X as a factor
- Count the nodes in the given tree whose weight is a power of two
- Count the nodes in the given tree whose sum of digits of weight is odd
- Count the number of nodes at given level in a tree using BFS.
- Count Non-Leaf nodes in a Binary Tree
- Count the nodes in the given tree whose weight is prime
- Determine the count of Leaf nodes in an N-ary tree
- Check if two nodes are in same subtree of the root node
- Count the nodes of the tree whose weighted string contains a vowel
- Count the nodes in the given tree whose weight is a powerful number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : SHUBHAMSINGH10