sudhir sharma

sudhir sharma

975 Articles Published

Articles by sudhir sharma

Page 31 of 98

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

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 268 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 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 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 next right node of a given key in C++

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

In this problem, we are given a binary Tree BT and a key value. Our task is to Find next right node of a given key.Binary Tree is a special data structure used for data storage purposes.Let’s take an example to understand the problem, Inputkey = 4Output5ExplanationThe element next to the node 4 is 5.Solution ApproachA simple solution to the problem is by traversing the binary tree using the level order traversal. And for the given key value, we will check if there exists an node next to node at the same level in the traversal. If Yes, return the ...

Read More

Find length of Diagonal of Hexagon in C++

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

In this problem, we are given an integer n denoting the length of the side of a regular hexagon. Our task is to Find length of Diagonal of Hexagon.Problem Description: Here, we have the side of a regular hexagon. And we need to find the length of the diagonal of the hexagon.Let’s take an example to understand the problem,  Input: a = 7Output: 12.11Solution ApproachTo solve the problem and find the length of diagonal which is given by the mathematical formula, Diagonal = 1.73 * aLet’s derive the formula, Here, we have a regular polygon of length a.The angle between the diagonal and ...

Read More

Find length of the largest region in Boolean Matrix in C++

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

In this problem, we are given a 2-D matrix of size nXm consisting of 0’s and 1’s only. Our task is to find the length of the largest region in the Boolean Matrix. Problem Description: If a cell contains 1, it is a filled Cell. We need to find the length of connected cells which are connected adjacent to each other horizontally or vertically or diagonally. Let’s take an example to understand the problem,  Input: matrix[4][5]{ {0, 1, 1, 0, 1},    {0, 0, 1, 1, 1},    {1, 0, 0, 0, 0},    {1, 0, 1, 0, 1} }Output: 6Explanation:  The number of connected filled ...

Read More

Find letter's position in Alphabet using Bit operation in C++

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

In this problem, we are given a string str consisting of english alphabets. Our task is to find the letter's position in the Alphabet using the Bit operation. Problem Description: Here, we will return the position of each character of the string as it is in english alphabets.The characters of the string are case-insensitive i.e. “t” and “T” are treated the same.Let’s take an example to understand the problem,  Input: str = “Tutorialspoint”Output: 20 21 20 15 18 9 1 12 19 16 15 9 14 20 Solution ApproachA simple solution to find a character's position is by finding its logical AND operation with 31.Program ...

Read More

Find longest length number in a string in C++

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

In this problem, we are given a string str consisting of character and alphabets only. Our task is to find the longest length number in a string. Problem Description: we need to find the length of the number i.e. consecutive numerical characters in the string.Let’s take an example to understand the problem,  Input: str = “code001tutorials34124point”Output: 34124Explanation:  Numbers in the string are001 - size 334124 - size 5Solution ApproachA simple solution to the problem is by traversing the sting and finding the number’s length and its starting index. We will store the starting position and count of characters in the string for each number ...

Read More

Find M-th number whose repeated sum of digits of a number is N in C++

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

In this problem, we are given two positive numbers N and M. Our task is to find the M-th number whose repeated sum of digits of a number is N. Problem description: Here, we need to find the Mth number whose sum of digits till the sum becomes single digit is equal to N.Let’s take an example to understand the problem,  Input: N = 4 M = 6Output: 49Solution ApproachA simple solution of the problem, is by finding all numbers and count the number whose sum of digits is N, and return m-th number.Another solution to the problem is using formula to find M-th ...

Read More

Find m-th smallest value in k sorted arrays in C++

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

In this problem, we are given k different arrays of different sizes. Our task is to find m-th smallest value in k sorted arrays. Problem Description: Here, we need to find m-th smallest element of the merged array of all k arrays.Let’s take an example to understand the problem,  Input:         m = 4                   arr[][] = { {4 , 7},                                     {2, 5, 6},                       ...

Read More
Showing 301–310 of 975 articles
« Prev 1 29 30 31 32 33 98 Next »
Advertisements