C++ Articles - Page 253 of 719

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

147 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

170 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

403 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

218 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

261 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 product of indexes of next greater on left and right in C++ Program

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

353 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 of an increasing subsequence in C++ Program

sudhir sharma
Updated on 09-Dec-2020 12:10:11

205 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 an increasing subsequence of size 3 in C++ program

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

189 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,  Live Demo#include using namespace ... Read More

Maximum product of a triplet (subsequence of size 3) in array in C++ Program.

sudhir sharma
Updated on 09-Dec-2020 12:04:27

727 Views

In this problem, we are given an array arr[] consisting of n integers. Our task is to find the maximum product of a triplet (subsequence of size 3) in array. Here, we will be finding the triple with maximum product value and then return the product.Let’s take an example to understand the problem, Inputarr[] = {9, 5, 2, 11, 7, 4}Output693ExplanationHere, we will find the triplet that gives the maximum product of all elements of the array. maxProd = 9 * 11 * 7 = 693Solution ApproachThere can be multiple solutions to the problem. We will be discussing them here, ... Read More

Count of distinct rectangles inscribed in an equilateral triangle in C++

Sunidhi Bansal
Updated on 03-Dec-2020 07:50:15

186 Views

We are an equilateral triangle with side length. The goal is to count the number of distinct rectangles that can be present inside the triangle such that horizontal sides of the rectangle are parallel to the base. Also all end points of the rectangle touch the dots as shown.Let us understand with examplesInput − sides=3Output − Count of distinct rectangles inscribed in an equilateral triangle are − 1Explanation − The figure above shows the rectangle.Input − sides=10Output − Count of distinct rectangles inscribed in an equilateral triangle are − 200Approach used in the below program is as followsAs from the ... Read More

Advertisements