Found 33676 Articles for Programming

Maximum Weight Difference in C++

Ayush Gupta
Updated on 09-Oct-2020 09:46:05

241 Views

In this problem, we are given an array arr[] and a number M. Our task is to create a program to calculate the Maximum Weight Difference in C++.Problem StatementWe will find M elements from the array such that the absolute difference between the sum and the sum of rest elements is maximum.Let’s take an example to understand the problem, Input: arr[] = {3, 1, 6, 9, 4} M = 3Ouput:15ExplanationWe will consider 4, 6, 9. The sum is 19. The absolute difference with the sum of rest numbers is|19 - 4| = 15Solution ApproachThe solution to the problem is based ... Read More

Maximum value of an integer for which factorial can be calculated on a machine in C++

Ayush Gupta
Updated on 09-Oct-2020 09:47:58

220 Views

In this problem, we need to create a program to find Maximum value of an integer for which factorial can be calculated on a machine in C++.Factorial of a number is a huge value, as it is the product of all values preceding it. And C++ can handle large values only upto a certain value by using its inbuilt function. We need to find this restriction.Solution ApproachWe will simply use the property of data types which is when the numbers exceed the maximum value a negative number is returned.We will use long long int which is the largest basic data ... Read More

Maximum value K such that array has at-least K elements that are >= K in C++

Ayush Gupta
Updated on 09-Oct-2020 09:48:49

319 Views

In this problem, we are given an array arr. Our task is to create a program to find the Maximum value K such that the array has at-least K elements that are >= K in C++.Problem DescriptionWe need to find a value K, that fulfills the condition that there are K or more elements in the array that are greater than or equal to K.Let’s take an example to understand the problem, Input:arr[] = {3, 5, 1, 7, 6, 6, 4, 8}Output:5ExplanationElements in the array that are greater than or equal to 5: 5, 6, 6, 7, 8.Solution ApproachA simple ... Read More

Maximum value in an array after m range increment operations in C++

Ayush Gupta
Updated on 15-Oct-2020 11:52:25

287 Views

In this problem, we are given an array arr[] of N elements initialized with 0. Our task is to create a program to find the Maximum value in an array after m range increment operations in C++.Problem DescriptionOn the array, we will perform m range increment operation of the type, update[L, R, K] = Add value K, to all elements in the range.After performing m operations on the array. We need to find the element with maximum value in the array.Let’s take an example to understand the problem, InputN = 6, m = 4 Update[][] = {{1, 4, 12}, {0, ... Read More

Maximum trains for which stoppage can be provided in C++

Ayush Gupta
Updated on 15-Oct-2020 11:56:44

312 Views

In this problem, we are given a number N denoting the number of platforms a station has with two tracks each. And T trains will be passing the station whose arrival and departure time are given. Each train stops at a specific station. Our task is to create a program to find the Maximum trains for which stoppage can be provided in C++.Let’s take an example to understand the problem, InputN = 3, T = 5 Trains = {{0915, 0930, 2}, {0930, 0945, 1}, {0930, 1200, 1}, {0910, 0925, 3}, {0940, 1015, 1}}Output4ExplanationThe train schedules are, Train 1: Train will ... Read More

Maximum trace possible for any sub-matrix of the given matrix in C++

Ayush Gupta
Updated on 15-Oct-2020 12:00:47

349 Views

In this problem, we are given a two-dimensional array arr[][]. Our task is to create a program to find the Maximum trace possible for any sub-matrix of the given matrix in C++.Problem Descriptionwe need to find the maximum trace for any sub-matrix. The trace is the sum of elements of the main diagonal of the matrix.Let’s take an example to understand the problem, Inputarr[][] ={{-2, 5, 3},           {1, 6, 2},           {4, 3, 9}}Output15ExplanationFor the sub-array: {1, 6} {9, 3}Solution ApproachA simple solution is to find the max sum using the ... Read More

Maximum sum such that no two elements are adjacent - Set 2 in C++

Ayush Gupta
Updated on 15-Oct-2020 12:05:22

209 Views

In this problem, we are given an array arr[]. Our task is to create a program to find the Maximum sum such that no two elements are adjacent in C++.Problem DescriptionWe need to find the maximum sum of the sequence from the array such that no 2 numbers from the sum sequence are adjacent in the array.Let’s take an example to understand the problem, Inputarr[] = {5, 1, 3, 7, 9, 2, 5}Output22ExplanationTaking sum sequence from index 0 with alternate elements : 5 + 3 + 9 + 5 = 22 Taking sum sequence from index 1 with alternate elements ... Read More

Maximum sum such that no two elements are adjacent in C++

Ayush Gupta
Updated on 15-Oct-2020 12:07:39

233 Views

In this problem, we are given an array arr[]. Our task is to create a program to find the Maximum sum such that no two elements are adjacent in C++.Problem DescriptionWe need to find the maximum sum of the sequence from the array such that no 2 numbers from the sum sequence are adjacent in the array.Let’s take an example to understand the problem, Inputarr[] = {5, 1, 3, 7, 9, 2, 5}Output22ExplanationTaking sum sequence from index 0 with alternate elements : 5 + 3 + 9 + 5 = 22 Taking sum sequence from index 1 with alternate elements ... Read More

Find pairs with given product in a sorted Doubly Linked List in C++

Arnab Chakraborty
Updated on 25-Jul-2020 11:12:21

272 Views

ConceptWith respect of a given sorted doubly linked list of positive distinct elements, our taskis to determine pairs in the doubly linked list whose product is equal to given value x, without consuming any extra space.InputList = 1 2 4 5 6 8 9 x = 8Output(1, 8), (2, 4)InputList1 = 1 2 3 4 5 6 7 x = 6Output(1, 4), (2, 3)MethodAccording to a Simple Approach for this problem, we traverse the linked list implementing two nested loops and determine all pairs and verify for the ... Read More

Find pair of rows in a binary matrix that has maximum bit difference in C++

Arnab Chakraborty
Updated on 25-Aug-2020 12:06:43

182 Views

Suppose we have a binary matrix; we have to find the pair of rows in the given matrix that has maximum bit difference.So, if the input is like matrix, then the output will be [2, 3] as bit difference between rows 2 and row 3 is 4, this is maximum.To solve this, we will follow these steps −Define Trie structure, with value and two children.Define a function get_max_bit_diff(), this will take root of a trie, matrix, n, row_index, temp := root, count := 0for initialize i := 0, when i < n, update (increase i by 1), do−if child[ matrix[row_index, ... Read More

Advertisements