Hafeezul Kareem has Published 345 Articles

Number of non-negative integral solutions of sum equation in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 26-Oct-2021 18:32:38

149 Views

In this tutorial, we are going to write a program that finds the number non-negative integral solution of sum equation.The sum equation is x + y + z = n. You are given the number n, you need to find the number of solutions for the equation. Let's see an ... Read More

Number of nodes greater than a given value in n-ary tree in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 26-Oct-2021 18:25:17

276 Views

Given an n-ary tree and a number, we have to count the number of nodes greater than the given number. Let's see an example.Inputtree = [[4], [1, 2], [3, 5]] n = 2Output3There are 3 nodes with values that are greater than n.AlgorithmInitialise the n-ary tree.Initialise the count to 0.Increment ... Read More

Number of NGEs to the right in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 26-Oct-2021 15:27:07

139 Views

You are given an array and the index of the target element. We have to count the number of elements greater than the given element to its right. Let's see an example.Inputarr = [2, 3, 5, 1, 4, 2, 6] index = 3Output3The target index element is 1. There are ... Read More

Number of n digit stepping numbers in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 26-Oct-2021 15:21:46

109 Views

The stepping number is a number where the difference between the consecutive digits is 1. You are given a number n representing the number of digits. You need to count the total number of stepping numbers with n digits.Let's see an example.Input2Output17The lowest number of 2 digits is 10 and ... Read More

Number of moves required to guess a permutation in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 26-Oct-2021 15:14:20

85 Views

Given a number N, we need to find the moves required to guess the permutation in the worst-case scenario. The number of moves required to guess the permutation will be n!. Let's take an example.Input5Output129When we have 5 elements, then we have 5 ways to guess, and 4 ways when ... Read More

Number of leaf nodes in the subtree of every node of an n-ary tree in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 26-Oct-2021 15:07:20

300 Views

In this tutorial, we are going to write a program that finds the number of leaf nodes for every node in the n-ary tree.Given a n-ary tree, we have to find the number of leaf nodes for every subtree. Let's see an example.InputN = 8 tree = [[2, 3], [], ... Read More

Number of leading zeros in binary representation of a given number in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 26-Oct-2021 14:53:53

424 Views

Given a number, we have to find the number of leading zeroes in the binary representation of it. Assuming total bits to be 32. Let's see an example.Input5Output25The binary representation of 5 is 00000...00101. The number of leading zeroes are 29.AlgorithmInitialise the number n.Find the binary representation of n.Subtract the ... Read More

Number of Larger Elements on right side in a string in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 26-Oct-2021 14:45:24

105 Views

Given a string, we have to count the number of larger elements on right side of each character. Let's see an example.Inputstring = "abc"Output2 1 0There are 2 larger elements than a on its right side.There is 1 larger element than b on its right side.There are 0 larger elements ... Read More

Number of integral solutions of the equation x1 + x2 +…. + xN = k in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 26-Oct-2021 14:35:40

256 Views

The solutions for the equation areThe number of non-negative integral solutions of the equation are $\left(\begin{array}{c}n-k+1\ k\end{array}\right)$The number of positive integral solutions of the equation are $\left(\begin{array}{c}k-1\ n-1\end{array}\right)$Add both to get the required answer. Let's see an example.Inputn = 4 k = 7Output140 AlgorithmInitialise the numbers n and k.Find the ... Read More

Number of Integral Points between Two Points in C++

Hafeezul Kareem

Hafeezul Kareem

Updated on 26-Oct-2021 13:40:00

371 Views

In this tutorial, we are going to write a program the finds the number of integral points between the given two points.The number of points between two given points will be gcd(abs(x2), abs(y1-y2)) - 1.If the line joining is parallel to x-axis, then the number of integral points will be ... Read More

Advertisements