sudhir sharma

sudhir sharma

975 Articles Published

Articles by sudhir sharma

Page 34 of 98

Maximum product of an increasing subsequence of size 3 in C++ program

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

In this problem, we are given an array arr[] of n positive integers. Our task is to create a program to find the Maximum product of an increasing subsequence of size 3.Problem Description − Here, we need to find the maximum product of 3 elements of the array such that they form an increasing subsequence and array index are also increasing i.e.arr[i]*arr[j]*arr[k] is maximum, arr[i] j to n−1Step 1.1.1.1 −if(arr[j] < arr[k]) −> find prod = arr[i]*arr[j]*arr[k].Step 1.1.1.2 −if(maxProd > prod) −> maxProd = prod.Step 2 −Return maxProd.ExampleProgram to illustrate the working of our solution, #include using namespace std; ...

Read More

Maximum product of an increasing subsequence in C++ Program

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

In this problem, we are given an array arr[] of size n. Our task is to find the maximum product of an increasing subsequence.Problem Description − We need to find the maximum product of increasing subsequence of any size possible from the elements of the array.Let’s take an example to understand the problem, Inputarr[] = {5, 4, 6, 8, 7, 9}Output2160ExplanationAll Increasing subsequence: {5, 6, 8, 9}. Prod = 2160 {5, 6, 7, 9}. Prod = 1890 Here, we have considered only max size subsequence.Solution ApproachA simple solution to the problem is by using a dynamic programming approach. For this, ...

Read More

Maximum product of indexes of next greater on left and right in C++ Program

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

In this problem, we are given an array arr[]. Our task is to create a program to calculate the Maximum product of indexes of next greater on left and right.Problem Description −For the given array we need to find the product of maximum value of left[i]*right[i]. Both arrays are defined as −left[i] = j, such that arr[i] j. right[i] = j, such that arr[i] < arr[j] and i < j. *The array is 1 indexed.Let’s take an example to understand the problem, Inputarr[6] = {5, 2, 3, 1, 8, 6}Output15ExplanationCreating left array, left[] = {0, 1, 1, 3, 0, ...

Read More

Maximum product subset of an array in C++ program

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

In the problem, we are given an array arr[] of n integer values. Our task is to create a program to find the Maximum product subset of an array.Problem Description − Here, we need to calculate the maximum possible product of a subset of elements of an array.Subset − An array sub[] is a subset of array arr[] if all elements of sub[] are present in arr[].Let’s take an example to understand the problem, Inputarr[] = {4, 5, 2, −1, 3}Output40ExplanationSubset sub[] = {4, 5, 2} Prod = 4*5*2 = 40Solution ApproachA simple and easy approach to solve the problem ...

Read More

Maximum size of sub-array that satisfies the given condition in C++ program

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

In this problem, we are given an array arr[] of n integers. Our task is to create a program to find the maximum size of sub-array that satisfies the given condition.Problem Description − We need to find the length of largest subarray that satisfies any one of the below condition, arr[k] > arr[k+1], if k is odd and arr[k] < arr[k+1], if k is even. For all elements of the subarray.arr[k] < arr[k+1], if k is odd and arr[k] > arr[k+1], if k is even. For all elements of the subarray.Here, k is the index of the element of the ...

Read More

Maximum sub-tree sum in a Binary Tree such that the sub-tree is also a BST in C++ program

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

In this problem, we are given a binary tree BT. Our task is to create a program to find the Maximum sub−tree sum in a Binary Tree such that the sub−tree is also a BST.Binary Tree has a special condition that each node can have a maximum of two children.Binary Search Tree is a tree in which all the nodes follow the below−mentioned propertiesThe value of the key of the left sub-tree is less than the value of its parent (root) node's key.The value of the key of the right subtree is greater than or equal to the value of ...

Read More

Maximum subarray size, such that all subarrays of that size have sum less than k in C++ program

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

In this problem, we are given an array arr[] consisting of n positive integers and an integer k. Our task is to create a program to find the Maximum subarray size, such that all subarrays of that size have sum less than k.Problem Description − we need to find the largest size of a subarray, such that all subarray created of the size from the elements of the array will have the sum of elements less than or equal to k.Let’s take an example to understand the problem, Inputarr[n] = {4, 1, 3, 2}, k = 9Output3ExplanationAll subarrays of size ...

Read More

Maximum Subarray Sum Excluding Certain Elements in C++ program

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

In this problem, we are given two arrays arr1[] of size n and arr2[] of size m. Our task is to create a program to find the maximum subarray sum excluding certain elements.Problem Description − We need to find the maximum subarray sum from elements of the array arr1[] that are not present in arr2[].Let’s take an example to understand the problem, Inputarr1[] = {4, 5, 7, 2, 9}, arr2[] = {1, 9, 2, 7}Output9Explanationarr1 after removal of elements of arr2[] = {4, 5} Both can form a subarray, hence sum = 4+5 = 9.Solution ApproachA simple solution to the ...

Read More

Maximum subarray sum in an array created after repeated concatenation in C++ Program

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 258 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 subarray sum in an array created after repeated concatenation.Problem Description − We will find the maximum sum of the subarray is taken from the array which is created after repeating arr, k times.ExampleLet’s take an example to understand the problem.Inputarr[] = {−9, −5, 14, 6} k = 2Output26ExplanationNew array after repeating : {−9, −5, 14, 6, −9, −5, 14, 6} Subarray with maximum sum = {14, 6, −9, −5, 14, 6} Sum = ...

Read More

Maximum subsequence sum such that no three are consecutive in C++ Program

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

In this problem, we are given an array arr[] consisting of n positive integers. Our task is to create a program to find the maximum subsequence sum such that no three are consecutive.Problem Description − Here, we need to find the sum of sequences created from the array such that there are no three consecutive elements.Consecutive elements of an array are those elements that have followed the same order of index.arr[0], arr[1], arr[2], …Let’s take an example to understand the problem, Inputarr[] = {5, 9, 12, 15}Output32ExplanationSum = 5 + 12 + 15 = 32Solution ApproachA simple solution to the ...

Read More
Showing 331–340 of 975 articles
« Prev 1 32 33 34 35 36 98 Next »
Advertisements