Get Maximum Sum
Learn this problemProblem statement
Note π - might be a sister problem of Get Maximum Sum π¦
Developers at Amazon are working on a prototype for a utility that compresses a n x n matrix, data, with the help of a
compression rate represented by an array, factor. The utility returns an integer which is the maximum sum of
exactly x elements of the matrix such that the number of elements taken from the ith row does not exceed factor[i]
for all 0 <= i < n. The utility returns -1 if the compression cannot be performed.
Given arrays data and factor, find the maximum sum to perform compression under the given constraints, or -1 if it is not possible.
Function
getMaximumSum(data: int[][], factor: int[], x: int) β long
Complete the function getMaximumSum in the editor.
getMaximumSum has the following parameters:
int factor[n]: the rate of compression for each element of dataint data[n][n]: the square matrix of dataint x: the number of elements to choose
Returns
long int: the maximum sum of health of the selected servers
π£ πͺspikeπ rocks! π
Examples
Example 1
data = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]factor = [1, 2, 1]x = 2return = 15Constraints
1 β€ n β€ n β€ 10001 β€ data[i][j] β€ 10^91 β€ factor[i] β€ n
More Amazon problems
- Drone Delivery RouteOA Β· Seen Aug 2026
- Package Dependency OrderPHONE SCREEN Β· ONSITE INTERVIEW Β· Seen Aug 2026
- Unfulfilled Customers by Inventory PriorityOA Β· Seen Aug 2026
- Calculate Beauty ValuesOA Β· Seen Aug 2026
- Maximize Distance to the Closest Occupied SeatONSITE INTERVIEW Β· Seen Aug 2026
- Package Delivery SystemOA Β· Seen Aug 2026
- Select Least Resource TasksOA Β· Seen Aug 2026
- Maximum Length-K Window Sum over Sparse SegmentsOA Β· Seen Aug 2026