Posts that are related to Recursion.

Sum of maximum of all subarrays | Divide and Conquer

Given an array arr[] of length N, the task is to find the sum of the maximum elements of every possible sub-array of the array.… Read More »

Maximum sum in an array such that every element has exactly one adjacent element to it

Given an array arr[] of N integers, you can select some indexes such that every selected index has exactly one other selected index adjacent to… Read More »

Generate all unique partitions of an integer | Set 2

Given a positive integer n, the task is to generate all possible unique ways to represent n as sum of positive integers. Examples: Input: 4… Read More »

Number of ways to reach the end of matrix with non-zero AND value

Given an N * N matrix arr[][] consisting of non-negative integers, the task is to find the number of ways to reach arr[N – 1][N… Read More »

GCD from root to leaf path in an N-ary tree

Given an N-ary tree and an array val[] which stores the values associated with all the nodes. Also given are a leaf node X and… Read More »

Sum of the mirror image nodes of a complete binary tree in an inorder way

Given a complete binary tree, the task is to find the sum of mirror image nodes in an inorder way i.e. find the inorder traversal… Read More »

Check if given Preorder, Inorder and Postorder traversals are of same tree | Set 2

Given Preorder, Inorder and Postorder traversals of some tree. The task is to check if they all are of the same tree. Examples: Input :… Read More »

XOR of all the nodes in the sub-tree of the given node

Given an n-ary tree and Q queries where each query consists of an integer u which denotes a node. The task is to print the… Read More »

Minimum number of cubes whose sum equals to given number N

Given an integer n, the task is to find the minimum number of cubes whose sum equals to N. Examples: Input: N = 496 Output:… Read More »

Count unique numbers that can be generated from N by adding one and removing trailing zeros

Given a number N. Add one to the number in the first step and if the number has trailing zeros, remove all the trailing zeros… Read More »

Find the node whose xor with x gives minimum value

Given a tree, and the weights of all the nodes and an integer x, the task is to find a node i such that weight[i]… Read More »

Find maximum product of digits among numbers less than or equal to N

Given an integer N > 0, the task is to find the maximum product of digits among numbers less than or equal to N. Examples:… Read More »

Number of subsequences with zero sum

Given an array arr[] of N integers. The task is to count the number of sub-sequences whose sum is 0. Examples: Input: arr[] = {-1,… Read More »

Find triplet such that number of nodes connecting these triplets is maximum

Given a Tree with N nodes, the task is to find a triplet of nodes (a, b, c) such that the number of nodes covered… Read More »

Print path from root to all nodes in a Complete Binary Tree

Given a number N which is the total number of nodes in a complete binary tree where nodes are number from 1 to N sequentially… Read More »