C++ Articles

Page 26 of 597

Find N'th item in a set formed by sum of two arrays in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 270 Views

In this problem, we are given two sorted arrays arr1[] and arr2[] of size m and an element N. Our task is to Find Nth item in a set formed by the sum of two arrays.Code description − Here, we will create a set that consists of the sum of element one of arr1 and one of arr2 i.e. sum = arr1[i] + arr2[j], where are i , j < m. For N, we need to find the value of the Nth element of the set.Let’s take an example to understand the problem, Inputarr1[] = {3, 1, 5} , arr2[] = ...

Read More

Find median in row wise sorted matrix in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 362 Views

In this problem, we are given a 2D array mat[r][c] whose elements are sorted row-wise. Our task is to Find median in a row-wise sorted matrix.Description − we need to find the median of elements of the matrix.Let’s take an example to understand the problem, Inputmat = {    {2, 4, 7},    {5, 6, 8},    {4, 8, 9} }Output6ExplanationThe elements of the matrix stored in array are &minus{2, 4, 4, 5, 6, 7, 8, 8, 9} The median is 6.Solution ApproachA simple solution to the problem is by storing all elements of the array. Then finding the median ...

Read More

Find n'th number in a number system with only 3 and 4 in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 2K+ Views

In this problem, we are given an element N. we need to find the N’th number in a number system with only 3 and 4.The number system consists of elements 3, 4, 33, 34, 43, 44, 333, 334, 343, 344, …Let’s take an example to understand the problem, InputN = 6Output44ExplanationThe numbers of the number system are − 3, 4, 33, 34, 43, 44...Solution ApproachThe number system is similar to the binary number system but the number 0 is replaced by 3 and number 1 is replaced by 4.Let’s say this as sBinary.So, number Nth number is (n-1)’s Sbinary conversion.With ...

Read More

Find Minimum Depth of a Binary Tree in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 540 Views

In this problem, we are given a binary tree. Our task is to Find Minimum Depth of a Binary Tree.Binary Tree has a special condition that each node can have a maximum of two children.The minimum depth of a binary tree is the shortest path between the root node to any leaf node.Let’s take an example to understand the problem, InputOutput2Solution ApproachThe solution to the problem is by traversing the binary tree and counting the heights. This can be done by recursively calling for the child node of the node for each node non-leaf node and return 1 for each ...

Read More

Find minimum number of merge operations to make an array palindrome in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 962 Views

In this problem, we are given an array arr[] consisting of n positive numbers. Our task is to Find minimum number of merge operations to make an array palindrome.Palindrome array are similar to palindrome strings, the elements at index i and n-i should be the same.Example{5, 1, 7, 2, 7, 1, 5}Problem Description − We need to make the array palindrome by performing operations on it. And the only operation which is valid on the array is the merge operation in which we will add elements at index i and i+1.We need to return the minimum number of such operations ...

Read More

Find next greater number with same set of digits in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 1K+ Views

In this problem, we are given an element N. We need to find the next greater number with the same set of digits. We need to find the smallest number with the same digit which is greater than N.Let’s take an example to understand the problem, InputN = "92534"Output92543Solution ApproachA simple solution to the problem to find the next greater element is by the following approach −Traverse the number from least significant bit to most significant bit. And stop when the current element is smaller than the last element.After this search for the smallest element in the remaining array. And ...

Read More

Find minimum operations needed to make an Array beautiful in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 636 Views

In this problem, we are given a binary array bin[] consisting n binary values which happen to be 0 and 1. Our task is to find minimum operations needed to make an Array beautiful.Beautiful array is a special type of binary array which consists of a pattern of alternate 0’s and 1’s.Problem Description − We need to find the number operations that are required to make the array beautiful. An operations consists of these steps −Step 1 − Cut the array into two halves.Step 2 − Reverse any one of the two halves.Step 3 − Join then halves back.We will ...

Read More

Find minimum possible size of array with given rules for removing elements in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 628 Views

In this problem, we are given an array of n numbers and an integer value k. Our task is to Find minimum possible size of the array with given rules for removing elements.Problem Description − we need to minimise the number of elements in the array. By using the follow deletion operation, The number of elements that can be removed at once is 3. The removal is possible if the three elements satisfy the two given conditions, Cond 1 − Three elements should be adjacent.>Cond 2 − the difference between two nearby elements is k, i.e. arr[i + 1] = ...

Read More

Find nth Hermite number in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 195 Views

In this problem, we are given an integer value N. Our task is to create a program to Find nth Hermite number.Hermite Number is a number is the value of hermite number when there are 0 arguments.Nth hermite Number is HN = (-2) * (N - 1) * H(N-2) The base values are H0 = 1 and H0 = 0.The hermite sequence is − 1, 0, -2, 0, 12, 0, -120, 0, 1680, 0….Let’s take an example to understand the problem, InputN = 7Output0InputN = 6Output-120Solution ApproachA simple solution to the problem is using the formula for hermite number. This ...

Read More

Find mirror of a given node in Binary tree in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 274 Views

In this problem, we are given a binary tree. Our task is to Find mirror of a given node in the Binary tree. We will be given a node, and find the mirror image of that node in the opposite subtree.Let’s take an example to understand the problem, InputOutputmirror of B is E.Solution ApproachOne simple solution to solve the problem is by using the recursion from the root using two pointers for left subtree and right subtree. Then for the target value if any mirror is found return the mirror otherwise recur other nodes.Program to illustrate the working of our ...

Read More
Showing 251–260 of 5,962 articles
« Prev 1 24 25 26 27 28 597 Next »
Advertisements