Problem · Matrix

Flipping Matrix

Learn this problem
MediumZomato / EternalONSITE INTERVIEW

Problem statement

You are given a 2N x 2N matrix of integers. You may reverse any row or any column any number of times and in any order.

Return the maximum possible sum of the upper-left N x N submatrix, covering rows 0 through N - 1 and columns 0 through N - 1.

Function

maxUpperLeftSubmatrixSum(matrix: int[][]) → int

Examples

Example 1

matrix = [[112,42,83,119],[56,125,56,49],[15,78,101,43],[62,98,114,108]]return = 414

For each target cell in the upper-left quadrant, choose the largest value among the four cells that can be moved there by row and column reversals. The chosen values are 119, 114, 56, and 125, for a total of 414.

The source shared the rule but did not include this exact sample. FastPrep added this small example so the behavior can be checked directly.

More Zomato / Eternal problems

drafts saved locally
public int maxUpperLeftSubmatrixSum(int[][] matrix) {
  // write your code here
}
matrix[[112,42,83,119],[56,125,56,49],[15,78,101,43],[62,98,114,108]]
expected414
checking account