In this problem, we are given two arrays arr1[] and arr2[], and two numbers N and M.N gives the number of elements taken from arr1.M gives the number of elements taken from arr2.We need to select one of the elements from arr1[i] to arr2[i], for whichmakes the sum maximum, but maximum N can be taken from arr1 and M from arr2.Our task is to create a program to find the maximum sum by picking elements from two arrays in order in C++.Let’s take an example to understand the problem, Inputarr1[] = {5, 1, 6, 2, 8, 9} arr2[] = {8, ... Read More
In this problem, we are given an array arr[] of n integers. Our task is to create a program to find the Maximum sum alternating subsequence starting from the first element of the array.An alternating subsequence is a subsequence in which elements are increasing and decreasing in an alternating order i.e. first decreasing, then increasing, then decreasing. Here, the reverse alternating subsequence is not valid for finding the maximum sum.Let’s take an example to understand the problem, Inputarr[] = {5, 1, 6, 2, 4, 8, 9}Output27ExplanationStarting element: 5, decrease: 1, increase: 6, decrease: 2, increase:4, N.A. Here, we can use ... Read More
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
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
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
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
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
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
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
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
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP