Found 7347 Articles for C++

Maximum sum of increasing order elements from n arrays in C++

Ayush Gupta
Updated on 09-Sep-2020 13:05:50

117 Views

In this tutorial, we will be discussing a program to find maximum sum of increasing order elements from n arrays.For this we will be provided with N arrays of M size. Our task is to find the maximum sum by selecting one element from each array such that element from the previous array is smaller than the next one.Example Live Demo#include #define M 4 using namespace std; //calculating maximum sum by selecting //one element int maximumSum(int a[][M], int n) {    for (int i = 0; i < n; i++)       sort(a[i], a[i] + M);    int sum ... Read More

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

Ayush Gupta
Updated on 09-Sep-2020 13:03:39

92 Views

In this tutorial, we will be discussing a program to find maximum product of indexes of next greater on left and right.For this we will be provided with an array of integers. Our task is to find the element with maximum Left-Right product (L(i)*R(i) where L(i) is closest index on left side and greater than current element and R(i) is closest index on right side and greater than current element).Example Live Demo#include using namespace std; #define MAX 1000 //finding greater element on left side vector nextGreaterInLeft(int a[], int n) {    vector left_index(MAX, 0);    stack s;    for (int ... Read More

Maximum product of an increasing subsequence in C++

Ayush Gupta
Updated on 09-Sep-2020 13:01:04

75 Views

In this tutorial, we will be discussing a program to find maximum product of an increasing subsequence.For this we will be provided with an array of integers. Our task is to find the maximum product of any subsequence of the array with any number of elements.Example Live Demo#include #define ll long long int using namespace std; //returning maximum product ll lis(ll arr[], ll n) {    ll mpis[n];    //initiating values    for (int i = 0; i < n; i++)       mpis[i] = arr[i];    for (int i = 1; i < n; i++)       ... Read More

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

Ayush Gupta
Updated on 09-Sep-2020 12:59:02

81 Views

In this tutorial, we will be discussing a program to find maximum product of an increasing subsequence of size 3.For this we will be provided with an array of positive integers. Our task is to find a subsequence of three elements with the maximum product.Example#include using namespace std; //returning maximum product of subsequence long long int maxProduct(int arr[] , int n) {    int smaller[n];    smaller[0] = -1 ;    setS ;    for (int i = 0; i < n ; i++) {       auto j = S.insert(arr[i]);       auto itc = j.first;   ... Read More

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

Ayush Gupta
Updated on 09-Sep-2020 12:57:09

73 Views

In this tutorial, we will be discussing a program to find maximum product of a triplet (subsequence of size 3) in array.For this we will be provided with an array of integers. Our task is to find the triplet of elements in that array with the maximum productExample Live Demo#include using namespace std; //finding the maximum product int maxProduct(int arr[], int n){    if (n < 3)       return -1;    int max_product = INT_MIN;    for (int i = 0; i < n - 2; i++)       for (int j = i + 1; j ... Read More

Maximum product of 4 adjacent elements in matrix in C++

Ayush Gupta
Updated on 09-Sep-2020 12:54:21

202 Views

In this tutorial, we will be discussing a program to find maximum product of 4 adjacent elements in matrix.For this we will be provided with a square matrix. Our task is to find the maximum product of four adjacent elements which can be top, down, right, left, or diagonal.Example Live Demo#include using namespace std; const int n = 5; //finding maximum product int FindMaxProduct(int arr[][n], int n) {    int max = 0, result;    for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {     ... Read More

Maximum product from array such that frequency sum of all repeating elements in product is less than or equal to 2 * k in C++

Ayush Gupta
Updated on 09-Sep-2020 12:50:50

87 Views

In this tutorial, we will be discussing a program to find maximum product from array such that frequency sum of all repeating elements in product is less than or equal to 2 * k.For this we will be provided with an array and an integer k. Our task is to find the maximum product from the array given that the frequency sum of all digits must be smaller than or equal to 2 * k.Example Live Demo#include using namespace std; #define ll long long int //returning maximum product value ll maxProd(int arr[], int n, int k) {    ll product ... Read More

Maximum Product Cutting | DP-36 in C++

Ayush Gupta
Updated on 09-Sep-2020 12:48:26

99 Views

In this tutorial, we will be discussing a program to find maximum Product Cutting | DP-36.For this we will be provided with a rope of N meters. Our task is to cut the rope in different integer lengths such that the product of their lengths is the maximumExample Live Demo#include using namespace std; //finding maximum of two, three integers int max(int a, int b) {    return (a > b)? a : b; } int max(int a, int b, int c) {    return max(a, max(b, c)); } //returning maximum product int maxProd(int n) {    if (n == 0 ... Read More

Maximum power of jump required to reach the end of string in C++

Ayush Gupta
Updated on 09-Sep-2020 12:46:23

216 Views

In this tutorial, we will be discussing a program to find maximum power of jump required to reach the end of string.For this we will be provided with a string of 0s and 1s. Our task is to find the maximum jump required to move from front to end of string given you can move to the same element as current one.Example Live Demo#include using namespace std; //finding maximum power jump int powerOfJump(string s) {    int count = 1;    int max_so_far = INT_MIN;    char ch = s[s.length() - 1];    for (int i = 0; i < s.length(); ... Read More

Maximum possible time that can be formed from four digits in C++

Ayush Gupta
Updated on 09-Sep-2020 12:44:22

272 Views

In this tutorial, we will be discussing a program to find maximum possible time that can be formed from four digits.For this we will be provided with an array consisting 4 digits. Our task is to find the maximum time (24 hour format) that can formed using those four digits.Example Live Demo#include using namespace std; //returning updated frequency map map getFrequencyMap(int arr[], int n) {    map hashMap;    for (int i = 0; i < n; i++) {       hashMap[arr[i]]++;    }    return hashMap; } //checking if the digit is present in frequency map bool hasDigit(map* ... Read More

Advertisements