Found 7347 Articles for C++

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

Ayush Gupta
Updated on 09-Sep-2020 12:41:24

74 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 Live Demo#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 ... Read More

Maximum Possible Product in Array after performing given Operations in C++

Ayush Gupta
Updated on 09-Sep-2020 12:34:38

180 Views

In this tutorial, we will be discussing a program to find maximum Possible Product in Array after performing given OperationsFor this we will be provided with an array of size N. Our task is to perform N-1 operations (changing a[j] → a[i]*a[j] and remove a[i] value or just remove the value of a[i] (only once)) such that the remaining values are the maximum ones only.Example Live Demo#include using namespace std; //printing operations void MaximumProduct(int a[], int n) {    int cntneg = 0;    int cntzero = 0;    int used[n] = { 0 };    int pos = -1; ... Read More

Maximum possible middle element of the array after deleting exactly k elements in C++

Ayush Gupta
Updated on 09-Sep-2020 12:32:14

163 Views

In this tutorial, we will be discussing a program to find maximum possible middle element of the array after deleting exactly k elementsFor this we will be provided with an array of size N and an integer K. Our task is to reduce K elements from the array such that the middle element of the resulting array is maximum.Example Live Demo#include using namespace std; //calculating maximum value of middle element int maximum_middle_value(int n, int k, int arr[]) {    int ans = -1;    int low = (n + 1 - k) / 2;    int high = (n + ... Read More

Maximum possible intersection by moving centers of line segments in C++

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

73 Views

In this tutorial, we will be discussing a program to find maximum possible intersection by moving centers of line segmentsFor this we will be provided with the center of three line segments and their length. Our task is to move their center by K distance to increase the length of intersection region.Example Live Demo#include using namespace std; //finding maximum intersection int max_intersection(int* center, int length, int k) {    sort(center, center + 3);    if (center[2] - center[0] >= 2 * k + length) {       return 0;    }    else if (center[2] - center[0] >= 2 ... Read More

Maximum possible difference of two subsets of an array in C++

Ayush Gupta
Updated on 09-Sep-2020 12:20:29

339 Views

In this tutorial, we will be discussing a program to find maximum possible difference of two subsets of an arrayFor this we will be provided with an array containing one or two instances of few random integers. Our task is to create two subsets of that array such that the difference of their sum is maximum and no subset contains repetitive numbers.Example Live Demo#include using namespace std; //finding maximum subset difference int maxDiff(int arr[], int n) {    int SubsetSum_1 = 0, SubsetSum_2 = 0;    for (int i = 0; i

Maximum points of intersection n lines in C++

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

144 Views

In this tutorial, we will be discussing a program to find maximum points of intersection n linesFor this we will be provided with a number of straight lines. Our task is to find the maximum number of intersections the given number of lines meet.Example Live Demo#include using namespace std; #define ll long int //finding maximum intersection points ll countMaxIntersect(ll n) {    return (n) * (n - 1) / 2; } int main() {    ll n = 8;    cout

Maximum points of intersection n circles in C++

Ayush Gupta
Updated on 09-Sep-2020 12:16:37

109 Views

In this tutorial, we will be discussing a program to find maximum points of intersection n circlesFor this we will be provided with the number of circles. Our task is to find the maximum number of intersections the given number of circles meet.Example Live Demo#include using namespace std; //returning maximum intersections int intersection(int n) {    return n * (n - 1); } int main() {    cout

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

Ayush Gupta
Updated on 09-Sep-2020 12:14:30

263 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 Live Demo#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 points covered after removing an Interval in C++

Ayush Gupta
Updated on 09-Sep-2020 12:08:40

186 Views

In this tutorial, we will be discussing a program to find maximum points covered after removing an IntervalFor this we will be provided with N intervals and the maximum range value . Our task is to find that one interval which when removed will give us the maxim numbers in the given range from 1 to maximum range valueExample Live Demo#include #define ll long long int using namespace std; //finding required interval void solve(int interval[][2], int N, int Q) {    int Mark[Q] = { 0 };    for (int i = 0; i < N; i++) {     ... Read More

Maximum points collected by two persons allowed to meet once in C++

Ayush Gupta
Updated on 09-Sep-2020 12:06:27

70 Views

In this tutorial, we will be discussing a program to find maximum points collected by two persons allowed to meet onceFor this we will be provided with a matrix with cells containing points. Our task is to find the path when two people starting from two corners meet such that they are having maximum points collected.Example Live Demo#include #define M 3 #define N 3 using namespace std; int findMaxPoints(int A[][M]) {    //storing points    int P1S[M+1][N+1], P1E[M+1][N+1];    memset(P1S, 0, sizeof(P1S));    memset(P1E, 0, sizeof(P1E));    int P2S[M+1][N+1], P2E[M+1][N+1];    memset(P2S, 0, sizeof(P2S));    memset(P2E, 0, sizeof(P2E));    for (int ... Read More

Advertisements