Amazon’s engineering team is developing a tool designed to minimize the size of an n x n grid named matrix, based on a compression ratio described by the array limit. Their challenge is to compute the highest possible sum of exactly x elements from the matrix while adhering to the following conditions:
Your task is to assist by computing the largest possible sum achievable under these restrictions.
Input Parameters:
Returns:
Examples
01 · Example 1
limit = [1, 2, 1] matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] x = 2 return = 15
The top selections from each row, respecting the limit constraints, are as follows:
Row 0: Choose 3 (since limit[0] = 1 allows only one pick)
Row 1: Pick 5 and 6 (as limit[1] = 2 permits two selections)
Row 2: Choose 9 (since limit[2] = 1 restricts to a single selection)
However, only x = 2 items can be chosen in total.
The most optimal selection strategy is to pick 6 from Row 1 and 9 from Row 2, maximizing the sum.
Constraints
- 1 ≤
n≤ 50 - 1 ≤
limit[i]≤n - 1 ≤
matrix[i][j]≤ 10^4 - 1 ≤
x≤n*n
More Amazon problems
- Get the Fewest Moves (~Operations~)~Seen Jun 2026
- Create Array Generator ServiceSeen Jun 2026
- Minimum Merge ConflictsOA · Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Drone Delivery RouteOA · Seen Jun 2026
- Sort Bug Report FrequenciesOA · Seen Jun 2026
- Maximum Equal Parts for PrefixesOA · Seen Jun 2026
- Count Promotional PeriodsOA · Seen Jun 2026
public long findMaxValue(int[] factor, int[][] data, int x) {
// write your code here
}
limit[1, 2, 1]
matrix[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
x2
expected15
sign in to submit