Narendra Kumar has Published 191 Articles

Maximum size subset with given sum in C++

Narendra Kumar

Narendra Kumar

Updated on 21-Jan-2020 11:30:13

763 Views

Problem statementGiven an array of N elements and sum. We need to find size of maximum size subset whose sum is equal to given sumExampleIf input array is arr = { 2, 3, 5, 10 } and sum = 20 then output will be 4 as −2 + 3 + ... Read More

Maximum profit from sale of wines in C++

Narendra Kumar

Narendra Kumar

Updated on 21-Jan-2020 11:17:53

203 Views

Problem statementGiven n wines in a row, with integers denoting the cost of each wine respectively. Each year you can sale the first or the last wine in the row. The price of wines increases over time. Let the initial profits from the wines be P1, P2, P3…Pn. On the ... Read More

Maximum prefix-sum for a given range in C++

Narendra Kumar

Narendra Kumar

Updated on 21-Jan-2020 11:10:19

712 Views

Problem statementGiven an array of n integers and q queries, each query having a range from l to r. Find the maximum prefix-sum for the range l – r.ExampleIf input array is arr[] = {-1, 2, 3, -5} and queries = 2 and ranges are: l = 0, r = ... Read More

Maximum Perimeter Triangle from array in C++

Narendra Kumar

Narendra Kumar

Updated on 21-Jan-2020 10:58:36

309 Views

Problem statementGiven an Array of non-negative integers. Find out three elements from the array which form a triangle of maximum perimeterExampleIf input array is {5, 1, 3, 5, 7, 4} then maximum perimeter is (7 + 5 + 5) = 17AlgorithmSort the array in non-increasing order. So, the first element ... Read More

Maximum OR sum of sub-arrays of two different arrays in C++

Narendra Kumar

Narendra Kumar

Updated on 10-Jan-2020 08:04:03

207 Views

Problem statementGiven two arrays of positive integers. Select two sub-arrays of equal size from each array and calculate maximum possible OR sum of the two sub-arrays.ExampleIf arr1[] = {1, 2, 4, 3, 2} andArr2[] = {1, 3, 3, 12, 2} then maximum result is obtained when we create following two ... Read More

Maximum number of fixed points using at most 1 swaps in C++

Narendra Kumar

Narendra Kumar

Updated on 10-Jan-2020 07:58:37

186 Views

Problem statementGiven a permutation of N elements from 0 to N-1. A fixed point is an index at which the value is same as the index i.e. arr[i] = i. You are allowed to make at most 1 swap. Find the maximum number of fixed points that you can get.ExampleIf ... Read More

Maximum number of edges to be added to a tree so that it stays a Bipartite graph in C++

Narendra Kumar

Narendra Kumar

Updated on 10-Jan-2020 07:56:14

331 Views

Problem statementA tree is always a Bipartite Graph as we can always break into two disjoint sets with alternate levels.In other words, we always color it with two colors such that alternate levels have same color. The task is to compute the maximum no. of edges that can be added ... Read More

Maximum number of edges in Bipartite graph in C++

Narendra Kumar

Narendra Kumar

Updated on 10-Jan-2020 07:53:40

349 Views

Problem statementGiven an integer N which represents the number of Vertices. The Task is to find the maximum number of edges possible in a Bipartite graph of N vertices.Bipartite GraphA Bipartite graph is one which is having 2 sets of vertices.The set are such that the vertices in the same ... Read More

Maximum length of segments of 0’s and 1’s in C++

Narendra Kumar

Narendra Kumar

Updated on 10-Jan-2020 07:40:21

246 Views

Problem statementGiven a string comprising of ones and zeros. The task is to find the maximum length of the segments of string such that a number of 1 in each segment is greater than 0ExampleIf input string is “10111000001011” the answer will 12 as follows −First segment is of length ... Read More

Maximum length of rod for Qth person in C++

Narendra Kumar

Narendra Kumar

Updated on 10-Jan-2020 07:36:21

145 Views

Problem statementGiven lengths of n rods in an array. If any person picks any rod, half of the longest rod (or (max + 1) / 2 ) is assigned and remaining part (max – 1) / 2 is put back. It may be assumed that sufficient number of rods are ... Read More

Previous 1 ... 4 5 6 7 8 ... 20 Next
Advertisements