Count all subtrees having the same value of nodes in a binary tree
Given a binary tree, count all subtrees in it such that every node in the subtree has the same value.
Ace your Coding Interview
Get hired by top tech companies with our comprehensive interview preparation.
Get StartedGiven a binary tree, count all subtrees in it such that every node in the subtree has the same value.
This post will discuss a few related problems that can be solved without using multiplication and division operators.
Given an unsorted integer array containing many duplicate elements, rearrange it such that the same element appears together and the relative order of the first occurrence of each element remains unchanged.
Given a BST, find the inorder successor of a given key in it. If the given key does not lie in the BST, then return the next greater key (if any) present in the BST.
Given a string, find the first non-repeating character in it by doing only one traversal of it.
Given a string, remove all adjacent duplicates from it. The algorithm should continue removing adjacent duplicates from the string till no duplicate is present in the result.
Given an unsorted integer array, print all triplets in it with a sum less than or equal to a given number.
Given an unsorted integer array whose elements lie in the range 0 to n-1 where n is the array size, calculate the frequency of all array elements in linear time and using constant space.
Given a binary search tree, modify it such that every key is updated to contain the sum of all greater keys present in the BST.
Given an M × N matrix, Function to find all common elements present in every row.
Given a directed weighted graph, report a negative-weight cycle in the graph, if any. A negative-weight cycle is a cycle in a graph whose edges sum to a negative value.
Given a weighted digraph (directed graph), find the least-cost path from a given source to a given destination with exactly m edges.