sudhir sharma

sudhir sharma

975 Articles Published

Articles by sudhir sharma

Page 36 of 98

Maximum sum possible for a sub-sequence such that no two elements appear at a distance < K in the array in C++ program

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

In this problem, we are given an array arr[] of size n and an integer k. Our task is to create a program to find the maximum sum possible for a subsequence such that no two elements appear at a distance < K in the array.Problem Description − We need to find the maximum sum of sub−seqeunce that considers elements that are k distance from each other.Let’s take an example to understand the problem, Inputarr[] = {6, 2, 5, 1, 9, 11, 4} k = 2Output16ExplanationAll possible sub−sequences of elements that differ by k or more. {6, 1, 4}, sum ...

Read More

Maximum sum subarray such that start and end values are same in C++ Program

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

In this problem, we are given an array arr[] of size n consisting of positive values. Our task is to create a program to find the maximum sum subarray such that start and end values are the same.Problem Description − Here, we need to find a subarray such that the elements at index i (starting index of subarray) and j (ending index of subarray) are the same i.e. arr[i] = arr[j]. And the sum of elements of the subarray is maximized.Let’s take an example to understand the problem, Inputarr[] = {2, 1, 3, 5, 6, 2, 4, 3}Output23ExplanationAll subarrays which ...

Read More

Maximum sum subsequence with at-least k distant elements in C++ program

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

In this problem, we are given an array arr[] of size n and a number k. Our task is to create a program to find the maximum sum subsequence with atleast k distant elements.Problem Description − We need to find the sum of subarrays such that the elements of the subarray are taken from the array whose index is at k distance and the sum is maximized.Let’s take an example to understand the problem, Inputarr[] = {2, 3, 7, 9, 2, 8, 3}Output15ExplanationAll subsequences that satisfy the given condition, {2, 9, 3}, Sum = 14 {3, 2}, Sum = 5 ...

Read More

Maximum sum such that no two elements are adjacent Alternate Method in C++ program

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

In this problem, we are given an array arr[] of size n consisting of positive values. Our task is to create a program to find the maximum subsequence sum in such a way that no two consecutive elements of the array.Problem Description − We need to find the sum of subarray which has elements of the array but no two adjacent elements of the array can be taken into consideration.ExampleLet’s take an example to understand the problem, Inputarr[] = {5, 2, 1, 9, 6}OutputExplanation −Subarray sum are : {5, 1, 6}, sum = 5 + 1 + 6 = 12 ...

Read More

Maximums from array when the maximum decrements after every access in C++ Program

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

In this problem, we are given an array arr[] of N integers and an integer m. Our task is to create a program to find the maximums from array when the maximum decrements after every access.Problem Description − We need to find the maximum sum of maximum elements of the array and decrease the max taken by one k times.Let’s take an example to understand the problem, Inputarr[] = {3, 6, 7, 8, 8}, k = 3OutputExplanationFirst iteration: array before = {3, 6, 7, 8, 8}, max = 8, sum = 8, array after update = {3, 6, 7, 7, ...

Read More

Dudeney Numbers in C++

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

A mathematical number defined in number theory in a given number base is a natural number equal to the perfect cube of another natural number such that the digit sum of the first natural number is equal to the digit sum of the second number(wikipedia).The number was found by Henry Dudeney. Its mathematical formula is −Here, we are given an integer n. Our task is to check whether the given number n is a dudeney number or not. Let’s take an example to understand the problem, Input: N = 17592Output: NoExplanation:  The given number is not a dudney number.Solution Approach −The solution lies ...

Read More

Element equal to the sum of all the remaining elements in C++

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

In this problem, we are given an array arr[] consisting of n positive values. Our task is to find the element equal to the sum of all the remaining elements of the array.Code Description: We need to find the element whose value is equal to the sum of all elements of the array except that element.Let’s take an example to understand the problem, Input: arr[] = { 5, 4, 17, 1, 7 }Output: 17Explanation −The sum of the rest of the element is (5 + 4 + 1 + 7 ) = 17, which is equal to the remaining element 17.Solution Approach −A simple ...

Read More

Elements greater than the previous and next element in an Array in C++

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

In this problem, we are given an array arr[] of n positive integers. Our task is to create a program to find the elements greater than the previous and next element in an Array. Code Description: We need to find the elements of the array that satisfy the condition, the element is greater that the element at index 1 less than it and also is greater than the element at index 1 greater than it.Let’s take an example to understand the problem, Input: arr[] = {3, 2, 5, 7, 3, 4, 5}Output: 7Explanation −Element with index one less than the current element, 5.Element with ...

Read More

Elements of an array that are not divisible by any element of another array in C++

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

In this problem, we are given two arrays arr1[] and arr2[]. Our task is to create a program to find the elements of an array that are not divisible by any element of another array. Problem Description: Here, we need to find all elements from arr1 that are not divisible by any elements of arr2.Let’s take an example to understand the problem, Input: arr1[] = {17, 15, 5, 12, 8}        arr2[] = {5, 4}Output: 17Explanation −Elements of arr1 and elements dividing them, 17 -> no element can divide it.15 -> 5 divides the element.5 -> 5 divides the element.12 -> 4 ...

Read More

Elements to be added so that all elements of a range are present in array in C++

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

In this problem, we are given an array arr[] consisting of n number. Our task is to create a program to find the number of elements to be added so that all elements of a range are present in array. Problem Description: Here, we need to find the number of elements that are needed to be added to the array to make sure that all elements of a range are present in the array. The range is from smallestElement of array to largestElement of array. Let’s take an example to understand the problem, Input: arr[] = {5, 8, 3, 1, 6, 2}Output: 2Explanation:The range is from ...

Read More
Showing 351–360 of 975 articles
« Prev 1 34 35 36 37 38 98 Next »
Advertisements