Narendra Kumar has Published 191 Articles

Maximum average sum partition of an array in C++

Narendra Kumar

Narendra Kumar

Updated on 31-Dec-2019 12:17:51

211 Views

Problem statementGiven an array, we partition a row of numbers A into at most K adjacent (non-empty) groups, then the score is the sum of the average of each group. What is the maximum score that can be scored?ExampleIf input array is {9, 2, 5, 3, 10} then we can ... Read More

Maximum average of a subarray of size of at least X and at most Y in C++

Narendra Kumar

Narendra Kumar

Updated on 31-Dec-2019 12:13:14

257 Views

Problem statementGiven an array arr[] and two integers X and Y. The task is to find a sub-array of size of at least X and at most Y with the maximum averageExampleIf input array is {2, 10, 15, 7, 8, 4} and x = 3 and Y = 3 then ... Read More

Maximum array from two given arrays keeping order same in C++

Narendra Kumar

Narendra Kumar

Updated on 31-Dec-2019 12:10:02

189 Views

Problem statementGiven two same sized arrays A[] and B[]. Task is to form a third array of same size. The result array should have maximum n elements from both array. It should have chosen elements of A[] first, then chosen elements of B[] in same order as they appear in ... Read More

Maximum area of quadrilateral in C++

Narendra Kumar

Narendra Kumar

Updated on 31-Dec-2019 12:05:22

309 Views

Problem statementGiven four sides of quadrilateral a, b, c, d, find the maximum area of the quadrilateral possible from the given sides.AlgorithmWe can use below Brahmagupta’s formula to solve this problem −√(s-a)(s-b)(s-c)(s-d)In above formula s is semi-perimeter. It is calculated as follows −S = (a + b + c + ... Read More

Maximum bitwise AND value of a pair in an array in C++

Narendra Kumar

Narendra Kumar

Updated on 31-Dec-2019 12:02:53

670 Views

Problem statementGiven an array of n positive elements. we need to find the maximum bitwise AND value generated by any pair of element from the array.ExampleIf input array is {10, 12, 15, 18} then maximum value of bitwise AND is 12.AlgorithmThe result of bitwise AND operations on single bit is ... Read More

Maximum and Minimum in a square matrix in C++

Narendra Kumar

Narendra Kumar

Updated on 31-Dec-2019 11:58:50

217 Views

Problem statementGiven a square matrix of order n*n, find the maximum and minimum from the matrixExampleIf given matrix is −{{15, 17, 19}, {5, 1, 7}, {14, 5, 16}} then Minimum number is 1 and maximum number is 19AlgorithmSelect two elements from the matrix one from the start of a row ... Read More

Maximum 0’s between two immediate 1’s in binary representation in C++

Narendra Kumar

Narendra Kumar

Updated on 31-Dec-2019 11:53:54

861 Views

Problem statementGiven a number n, the task is to find the maximum 0’s between two immediate 1’s in binary representation of given n. Return -1 if binary representation contains less than two 1’sExampleIf input number is 35 then its binary representation is −00100011In above binary representation there are 3 0’s ... Read More

Maximum element in min heap in C++

Narendra Kumar

Narendra Kumar

Updated on 31-Dec-2019 11:48:37

340 Views

Problem statementGiven a minimum heap find maximum element in that.ExampleIf input heap is −Then maximum element is 55AlgorithmIn minimum heap parent node will be lesser than its children. Hence we can conclude that a non-leaf node cannot be the maximum.Search maximum element in the leaf nodesExampleLet us now see an ... Read More

Maximizing Unique Pairs from two arrays in C++

Narendra Kumar

Narendra Kumar

Updated on 31-Dec-2019 11:45:55

359 Views

Problem statementGiven two arrays of equal size N, form maximum number of pairs by using their elements, one from the first array and second from the second array, such that an element from each array is used at-most once and the absolute difference between the selected elements used for forming ... Read More

Maximizing the elements with a[i+1] > a[i] in C++

Narendra Kumar

Narendra Kumar

Updated on 31-Dec-2019 11:41:55

368 Views

Problem statementGiven an array of N integers, rearrange the array elements such that the next array element is greater than the previous element arr[i+1] > arr[i]ExampleIf input array is {300, 400, 400, 300} then rearranged array will be −{300, 400, 300, 400}. In this solution we get 2 indices with ... Read More

Previous 1 ... 6 7 8 9 10 ... 20 Next
Advertisements