Found 7347 Articles for C++

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

sudhir sharma
Updated on 09-Dec-2020 13:00:51

98 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

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

sudhir sharma
Updated on 09-Dec-2020 12:54:07

128 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 Subarray Sum Excluding Certain Elements in C++ program

sudhir sharma
Updated on 09-Dec-2020 12:51:34

96 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 size, such that all subarrays of that size have sum less than k in C++ program

sudhir sharma
Updated on 09-Dec-2020 12:49:26

166 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 sub-tree sum in a Binary Tree such that the sub-tree is also a BST in C++ program

sudhir sharma
Updated on 09-Dec-2020 12:46:25

87 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 sub-matrix area having count of 1's one more than count of 0’s in C++ program

sudhir sharma
Updated on 09-Dec-2020 12:41:28

72 Views

In this problem, we are given a 2-D matrix of size nXn consisting of binary numbers (0/1). Our task is to create a program to find the Maximum submatrix area having count of 1’s one more than count of 0’s.Let’s take an example to understand the problem, Inputbin[N][N] = {    {0, 1, 0, 0},    {1, 1, 0, 0},    {1, 0, 1, 1},    {0, 1, 0, 1} }Output9Explanationsubmatrix : bin[1][0], bin[1][1], bin[1][2] bin[2][0], bin[2][1], bin[2][2] bin[3][0], bin[3][1], bin[3][2] is the largest subarray with more 1’s one more than 0’s. Number of 0’s = 4 Number of 1’s ... Read More

Maximum students to pass after giving bonus to everybody and not exceeding 100 marks in C++ Program

sudhir sharma
Updated on 09-Dec-2020 12:36:44

97 Views

In this problem, we are given an array stu[] of size n denoting the marks of students in the class. For each student, the maximum mark is 100 and a student needs 50 marks to pass the exam. Our task is to create a program to find the Maximum students to pass after giving a bonus to everybody and not exceeding 100 marks.Problem Description − We need to give bonus marks to students to pass but the bonus marks will be given to all students. Our task is to maximize the number of students that can pass the exam by ... Read More

Maximum size rectangle binary sub-matrix with all 1s in C++ Program

sudhir sharma
Updated on 09-Dec-2020 12:21:35

278 Views

In this problem, we are given a 2-D matrix bin[][] of size n*m that contains online binary numbers i.e. 0/1. Our task is to create a program to find the Maximum size rectangle binary sub-matrix with all 1s and Return the maximum area.Let’s take an example to understand the problem, Inputbin[][] = {    {1, 0, 1, 1, 1}    {0, 1, 1, 1, 1}    {0, 0, 1, 1, 1}    {1, 1, 1, 1, 1} }Output12ExplanationFor this rectangle the area with the maximum.1, 1, 1 1, 1, 1 1, 1, 1 1, 1, 1Solution ApproachTo solve the problem, ... Read More

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

sudhir sharma
Updated on 09-Dec-2020 12:18:45

109 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 product subset of an array in C++ program

sudhir sharma
Updated on 09-Dec-2020 12:15:45

171 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

Advertisements