Find Max Value

Problem Overview

  • Find the maximum sum of exactly x elements from an n×n matrix, with at most factor[i] elements chosen from row i; return -1 if not possible.
  • Input: factor[n], data[n][n], and x; Output: a long representing the max sum or -1.
  • Constraints: 1≤n≤50, 1≤factor[i]≤n, 1≤data[i][j]≤10^4, 1≤x≤n^2.
  • Context: models matrix compression with row-wise selection limits in data processing.
  • From Amazon interviews: a coding interview problem and interview question.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: