sudhir sharma

sudhir sharma

975 Articles Published

Articles by sudhir sharma

Page 47 of 98

Ways to place items in n^2 positions such that no row/column contains more than one in C++

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

In this problem, we are given an integer n such that there are n lines vertically and n horizontally that are placed such that there are n2 intersection between these lines. Our task is to find the total number of ways by which 4 items can be placed on these intersections insuch a way that no row and column contains more that one item.Let’s take an example to understand the problem, Inputn=4Output24ExplanationTo solve this problem, we will have to choose 4 horizontal lines from n lines that will have items which will be nC4. Now, every horizontal line has n ...

Read More

Sum of the alphabetical values of the characters of a string in C++

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

In this problem, we are given an array of string str[]. Our task is to find the score of all strings in the array. The score is defined as the product of the position of the string with the sum of the alphabetical values of the characters of the string.Let’s take an example to understand the problem, Input str[] = {“Learn”, “programming”, “tutorials”, “point” }Explanation Position of “Learn” − 1 →sum = 12 + 5 + 1 + 18 + 14 = 50. Score = 50Position of “programming” − 2 →sum = 16 + 18 + 15 + 7 + 18 + ...

Read More

Ways to paint stairs with two colors such that two adjacent are not yellow in C++

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

We are given n stairs and 2 colors (red and yellow) with which these stairs are to be painted. Our task is to count the number of ways in which we can paint the stairs such that no two consecutive steps will be yellow-colored.Let’s take an example to understand the problem, Input3Output5ExplanationThe ways in which stairs can be painted are YRY, RYR, YRR, RRY, RRR. here R denotes red color, Y denotes yellow color.To solve this problem, let’s see the number of ways the stairs can be painted.N = 1, ways(1) = 2 : R, YN = 2, ways(2) = ...

Read More

Sum of the alternate nodes of linked list in C++

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

In this problem, we are given a linked list. Our task is to print the sum of alternate nodes of the linked list.Linked list is a sequence of data structure which are connected together via links.Now, let’s get back to the problem. Here, we will add alternate nodes of the linked list. This means we will add nodes are positions 0, 2, 4, 6, …Let’s take an example to understand the problem,  Input 4 → 12 → 10 → 76 → 9 → 26 → 1Output 24Explanation considering alternate strings − 4 + 10 + 9 + 1 = 24To solve this problem, ...

Read More

Sum of the digits of a number N written in all bases from 2 to N/2 in C++

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

In this problem, we are given a number N. Our task is to create a program to find the sum of the digits of the number N in bases from 2 to N/2.So, we have to convert the base of the number to all bases from 2 to N/2 i.e. for n = 9, bases will be 2, 3, 4. And the find the sum of all digits in these bases.Let’s take an example to understand the problem, Input N = 5Output 2Explanation  base from 2 to N/2 is 2. 52 = 101, sum of digits is 2.To, solve this problem, we take ...

Read More

Ways to multiply n elements with an associative operation in C++

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

In this problem, we are given an integer n which is the number of elements. Our task is to create a program that counts the number of ways to multiply n elements with the associative operation.Associative operations return the same result irrespective of the manner the numbers are arranged.Let’s take an example to understand the problem, Input3Output12Explanation(x*(y*z)), (x*(z*y)), (y*(x*z)), (y*(z*x)), (z*(x*y)), (z*(y*x)), ((x*y)*z), ((y*x)*z), ((x*z)*y), ((z*x)*y), ((z*y)*x), ((y*z)*x).To solve this problem, we will try to find if there is any relation or any type of series that can be created so that we can generalize our results. Let’s see the ...

Read More

Sum of the elements from index L to R in an array when arr[i] = i * (-1)^i in C++

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

In this problem, we are given two numbers L and R. We also have an array arr[] such that arr[i] = i*(-1)^i. Our task is to create a program to calculate the sum of the element from index L to R in an array when arr[i] = i*(-1)^i.So, we need to find the sum of elements within the range [L, R] of the array.Let’s take an example to understand the problem, Input L = 2 , R = 6Output 4Explanation arr[] = {-1, 2, -3, 4, -5, 6} Sum = 2+ (-3) + 4 + (-5) + 6 = 4A simple solution to ...

Read More

Sum of the minimum elements in all connected components of an undirected graph in C++

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

In this problem, we are given an array arr of N numbers where arr[i] represents (i+1)th node. Also, there are M pairs of edges where u and v represent the node connected by the edge. Our task is to create a program to find the sum of the minimum elements in all connected components of an undirected graph. If a node has no connectivity to any other node, count it as a component with one node.Let’s take an example to understand the problem, Input arr[] = {2, 7, 5, 1, 2} m = 2 1 2 4 5Output 8Explanation Below is the graph ...

Read More

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

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

In this problem, we are given a complete binary tree. Our task is to create a program to find the sum of the mirror image nodes of a complete binary tree in an inorder way.Here, we have to find the inorder traversal of the left sun-tree, and then for each node, we will add the mirror image with it. This means if we are traversing the left leaf node, we will add the value of the right leaf node with it. As it is the mirror image node.Some important definitionsComplete binary tree is a binary tree where all levels have ...

Read More

Sum of the multiples of two numbers below N in C++

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

In this problem, we have given three integers M1, M2, and N. Our task is to create a program to find the sum of multiples of two numbers below N.Here, we will add all the elements below N which are multiples of either M1 or M2Let’s take an example to understand the problem, Input N = 13, M1 = 4, M2 = 6Output  20Explanation − Number that are multiples of 4 and 6 that are less than 13 are 4, 6, 8, 12.A simple solution to the problem is to be looping from 1 to N and adding all values that can ...

Read More
Showing 461–470 of 975 articles
« Prev 1 45 46 47 48 49 98 Next »
Advertisements