C++ Articles

Page 111 of 597

Minimum Size of Two Non-Overlapping Intervals in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 381 Views

Suppose we have a list of intervals where each interval contains the [start, end] times. We have to find the minimum total size of any two non-overlapping intervals, where the size of an interval is (end - start + 1). If we cannot find such two intervals, return 0.So, if the input is like [[2, 5], [9, 10], [4, 6]], then the output will be 5 as we can pick interval [4, 6] of size 3 and [9, 10] of size 2.To solve this, we will follow these steps −ret := infn := size of vsort the array v based ...

Read More

Maximum possible sum of a window in an array such that elements of same window in other array are unique in c++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 149 Views

In this tutorial, we will be discussing a program to find maximum possible sum of a window in an array such that elements of same window in other array are unique.For this we will be provided with two arrays with equal number of elements. Our task is to find the window in one element with maximum sum such that the same window in other array is unique.Example#include using namespace std; //returning maximum sum window int returnMaxSum(int A[], int B[], int n) {    //storing elements with their count    unordered_set mp;    int result = 0;    int curr_sum ...

Read More

Program to find GCD or HCF of two numbers using Middle School Procedure in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 1K+ Views

In this tutorial, we will be discussing a program to find GCD or HCF of two numbers using Middle School Procedure.For this we will be provided with two numbers. Our task is to find the GCD (greatest common divisor) or HCF (highest common factor) for the given values.Example#include #define MAXFACTORS 1024 using namespace std; //structure to store factorization typedef struct{    int size;    int factor[MAXFACTORS + 1];    int exponent[MAXFACTORS + 1]; } FACTORIZATION; void FindFactorization(int x, FACTORIZATION* factorization){    int i, j = 1;    int n = x, c = 0;    int k = 1; ...

Read More

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

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 302 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#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(); i++) ...

Read More

Maximum points from top left of matrix to bottom right and return back in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 438 Views

In this tutorial, we will be discussing a program to find maximum points from top left of matrix to bottom right and return backFor this we will be provided with matrix consisting of #-blocked path, *-points, .- allowed path. Our task is to go from one corner to another (right and below moves) and come back (left and top moves) such as to collect maximum pointsExample#include #define MAX 5 #define N 5 #define M 5 #define inf 100000 using namespace std; //calculating points int cost(char grid[][M], int row1, int col1, int row2, int col2) {    if (row1 == ...

Read More

Maximum Product Cutting | DP-36 in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 227 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#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 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
Ayush Gupta
Updated on 11-Mar-2026 185 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#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 of 4 adjacent elements in matrix in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 365 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#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 of a triplet (subsequence of size 3) in array in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 185 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#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 an increasing subsequence in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 149 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#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++)       for ...

Read More
Showing 1101–1110 of 5,962 articles
« Prev 1 109 110 111 112 113 597 Next »
Advertisements