Find Minimum or Maximum Element of an Array in C++

Ayush Gupta
Updated on 15-Sep-2020 14:21:28

14K+ Views

In this problem, we are given an array arr[] of n integers. Our task is to create a program to find the minimum and maximum element of an array in C++.Problem Description − Here, we have an array arr[]. The contains n integer values. We have to find the maximum value and minimum value out of all values of the array.Let’s take an example to understand the problem, Inputarr[] = {2, 1, 6, 9, 4, 10, 15, 21}Outputmax = 21 , min = 1Solution ApproachThere can be multiple solutions to the problem, One solution would be directly comparing elements of ... Read More

Maximum Product of Subsequence of Size K in C++

Ayush Gupta
Updated on 15-Sep-2020 14:20:26

506 Views

In this problem, we are given an array arr[] of integers and a number k. Our task is to create a program to find the Maximum product of subsequence of size k in C++.Problem Description − Here, we need to find the subsequence of size k, 1

Maximum Product of Two Non-Intersecting Paths in a Tree in C++

Ayush Gupta
Updated on 15-Sep-2020 14:19:33

316 Views

In this problem, we are given an undirected connected tree T with n nodes. Our task is to create a program to find the Maximum product of two nonintersecting paths in a tree in C++.Problem Description − To find the maximum product of two nonintersecting paths in a tree. We will find all the non-interesting paths and then find the product of their lengths.Let’s take an example to understand the problem, InputGraph −Output8ExplanationThe non-intersecting paths that are considered are C-A-B and F-E-D-G-H.The lengths are 2 and 4. Product = 8.Solution ApproachThe solution to this problem is by traversing the tree ... Read More

Maximum Product Quadruple Sub-Sequence of Size 4 in Array in C++

Ayush Gupta
Updated on 15-Sep-2020 14:18:33

399 Views

In this problem, we are given an array arr[]. Our task is to create a program to find the Maximum product quadruple (sub-sequence of size 4) in array in C++.Code description − Here, we need to find a quadruple (sub-sequence of size 4) such that the product of all elements is maximum.Let’s take an example to understand the problem, Inputarr[] = {4, -2, 5, -6, 8}Output840ExplanationThe quadruple, (-3, 5, -7, 8) with product 840.Solution ApproachThere can be multiple solutions to a given problem.One simple solution is using the direct method by traversing the array. Then finding all possible quadruples in ... Read More

Maximum Product Subarray Using Two Traversals in C++

Ayush Gupta
Updated on 15-Sep-2020 14:17:28

211 Views

In this problem, we are given an array arr[] of integers. Our task is to create a program to find the Maximum Product Subarray - Using Two Traversals in C++.Problem description − Here in the array, we will find the maximum product subarray using two traversals one from index 0 and another index (n-1).Let’s take an example to understand the problem, Inputarr[] = {4, -2, 5, -6, 0, 8}Output240ExampleSubarray = {4, -2, 5, -6} Maximum product = 4 * (-2) * 5 * (-6) = 240Solution ApproachTo solve this problem using two traversals. Here, we will find the maximum product ... Read More

Maximum Product Subarray with Negative Product Case in C++

Ayush Gupta
Updated on 15-Sep-2020 14:16:48

208 Views

In this problem, we are given an array of integers(positive as well as negative). Our task is to create a program to calculate the Maximum Product Subarray in C++.Problem Solution − Here, we have an array that contains positive, negative, and zero numbers. We need to find the product of subarrays created by elements of the array. And maximize the product of the subarray.Let’s take an example to understand the problem, Inputarr[] = {-1, 2, -7, -5, 12, 6}Output5040ExplanationThe subarray with the maximum product is {2, -7, -5, 12, 6}Product = 5040Solution ApproachTo solve this problem, we are given an ... Read More

Maximum Profit After Buying and Selling Stocks in C++

Ayush Gupta
Updated on 15-Sep-2020 14:15:16

852 Views

In this problem, we are given an array stkprice[] that denotes the price of a certain stock on i-th day. Our task is to create a program to calculate Maximum profit after buying and selling the stocks in C++.Problem Description − Here, we need to check when can be bought and sell the stock to gain profit. To gain profit, we need to buy the stock at a low price and sell it when the price goes up. And repeat the same when the drop is encountered again.Let’s take an example to understand the problem, Inputstkprice[] = {120, 310, 405, ... Read More

Maximum Rational Number or Fraction from an Array in C++

Ayush Gupta
Updated on 15-Sep-2020 14:14:32

284 Views

In this problem, we are given a 2-D array that contains rational numbers (one in each row). Our task is to create a program to calculate the maximum rational number (or fraction) from an array in C++.Problem Description − The 2-D array is of the form [n][2]. Each row has two integer values that denote the value of a and b in the equation of rational number, a/b. We need to find the greatest number out of all these rational numbers.Let’s take an example to understand the problem, Inputrat[][] = {    {3, 2},    {5, 7},    {1, 9}, ... Read More

Maximum Score After Flipping a Binary Matrix Atmost K Times in C++

Ayush Gupta
Updated on 15-Sep-2020 14:12:56

328 Views

In this problem, we are given a 2-D array arr[] consisting of boolean values (i.e 0’s and 1’s) and an integer K. Our task is to create a program to find the Maximum score after flipping a Binary Matrix atmost K times in C++.Problem Description − Here, for the 2-D array, and the k moves, we need to find the number that is created by the elements of the array. In each move, we will take a row or column and flip all the elements of the row or column. The choice will be done to keep in mind that ... Read More

Maximum Set Bit Sum in Array without Considering Adjacent Elements in C++

Ayush Gupta
Updated on 15-Sep-2020 14:11:22

203 Views

In this problem, we are given an array arr[] of integers. Our task is to create a program to calculate the Maximum set bit sum in array without considering adjacent elements in C++.Problem description − Here, we have an array arr[]. We have to find the number of set bits for each number. Then, we will find the maximum set bit sum in adjacent elements of the array. i.e. maximum sum for a[i] + a[i+2] ….Let’s take an example to understand the problem, Inputarr[] = {1, 4, 6, 7}Output4ExplanationArray with the element’s in binary formarr[] = {01, 100, 101, 111} ... Read More

Advertisements