## Next Larger element in n-ary tree in C++

Hafeezul Kareem

Updated on 25-Oct-2021 04:01:50

The n-ary tree is the tree with n children for each node. We are given a number n and we have to find the next larger element from the n-ary tree.We can find the solution by traversing through the n-ary tree and maintaining the result.AlgorithmCreate n-ary tree.Initialise a result.Write a ... Read More

## Next higher number with same number of set bits in C++

Hafeezul Kareem

Updated on 25-Oct-2021 03:55:28

We are given a number n, we have to find the number that is greater than n with same number of set bits as n in its binary representation.The digit 1 in the binary representation is called set bit.Let's see an example.Input124Output143AlgorithmInitialise the number n.Write a function get the count ... Read More

## Next higher number using atmost one swap operation in C++

Hafeezul Kareem

Updated on 25-Oct-2021 03:51:21

Given a number n, swap any two digits of the number so that the resulting number is greater than the number n. If it's not possible then print -1. Let's see an example.Input12345Output12354We have swapped the digits 4 and 5. And we got the higher number with one swap.AlgorithmIt's not ... Read More

## Next greater Number than N with the same quantity of digits A and B in C++

Hafeezul Kareem

Updated on 25-Oct-2021 03:46:00

Given N, A, and B. Find the number which is greater than N with the same number of A and B digits. Let's see an example.N = 1234 A = 2 B = 3We need to check for every possibility of the given number of digits. There are two digits to form ... Read More

## Next greater integer having one more number of set bits in C++

Hafeezul Kareem

Updated on 25-Oct-2021 03:38:03

We are given a number n, we have to find the number that is greater than n with one more set bit than n in its binary representation.The digit 1 in the binary representation is called set bit.Let's see an example.Input124Output125AlgorithmInitialise the number n.Write a function get the count of ... Read More

## Next Greater Element in C++

Hafeezul Kareem

Updated on 23-Oct-2021 18:16:34

The next greater element is the element that is first greater element after it. Let's see an example.arr = [4, 5, 3, 2, 1]The next greater element for 4 is 5 and the next greater element for elements 3, 2, 1 is -1 as there is no greater element after ... Read More

## Next greater element in same order as input in C++

Hafeezul Kareem

Updated on 23-Oct-2021 17:54:39

The next greater element is the element that is first greater element after it. Let's see an example.arr = [4, 5, 3, 2, 1]The next greater element for 4 is 5 and the next greater element for elements 3, 2, 1 is -1 as there is no greater element after ... Read More

## Newman-Shanks-Williams prime in C++

Hafeezul Kareem

Updated on 23-Oct-2021 17:48:11

The newman-shanks-williams prime sequence is as follows1, 1, 3, 7, 17, 41...If we generalise the sequence items, we geta0=1 a1=1 an=2*a(n-1)+a(n-2)AlgorithmInitialise the number n.Initialise the first numbers of the sequence 1 and 1.Write a loop that iterates till n.Compute the next number using the previous numbers.Update the previous two numbers.Return ... Read More

## Nesbitt’s Inequality in C++

Hafeezul Kareem

Updated on 23-Oct-2021 17:42:01

The nesbitt's inequality is (a/(b + c)) + (b/(c + a)) + (c/(a + b))>= 1.5, a > 0, b > 0, c > 0Given three number, we need to check whether the three numbers satisfy Nesbitt's inequality or not.We can test whether three number are satisfied nesbitt's inequality or ... Read More

## Neon Number in C++

Hafeezul Kareem

Updated on 23-Oct-2021 08:01:01

A neon number is a number where the sum of digits of the square of the number is equal to the number. Let's take an example.n = 9square = 81sum of digits of square = 8 + 1 = 9So, the number 9 is a neon number.We need to check ... Read More

Previous 1 ... 3 4 5 6 7 8 9 ... 38 Next