FastPrepPartition Matrix by Nonnegative Averages
Problems/Partition Matrix by Nonnegative Averages

Partition Matrix by Nonnegative Averages

ZipRecruiter logoZipRecruiter● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Four ZipRecruiter new-grad OA reports describe a four-quadrant partition by one row and one column, filtering non-negative values, averages rounded down, the goal of the minimum range, and, in the fullest report, the row and column tie-break. The reports leave out limits, a function signature, and reusable image data, so our version supplies those details.

For this exercise, use the callable contract below.

You are given an integer matrix with at least two rows and two columns. Choose a row index r and a column index c that divide the matrix into four non-empty rectangular regions:

  • top-left: rows 0 through r and columns 0 through c;
  • top-right: rows 0 through r and columns c + 1 through the last column;
  • bottom-left: rows r + 1 through the last row and columns 0 through c;
  • bottom-right: rows r + 1 through the last row and columns c + 1 through the last column.

For each region, ignore negative entries and compute the floor of the average of its nonnegative entries. A split is valid only when every region contains at least one nonnegative entry.

Minimize the difference between the largest and smallest of the four floored averages. If several splits have the same minimum difference, return the one with the smallest r, then the smallest c.

Return [r, c].

Function

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

Examples

Example 1

matrix = [[1,2,3],[4,5,6],[7,8,9]]return = [0,0]
matrix
012012314562789

The splits at [0,0], [0,1], [1,0], and [1,1] each have range 6, the minimum possible range. The row-then-column tie rule selects [0,0].

Example 2

matrix = [[0,10],[4,8]]return = [0,0]
matrix
010010148

The only split creates four one-cell regions, all with nonnegative entries, so the result is [0,0].

Constraints

  • 2 <= matrix.length <= 200
  • 2 <= matrix[i].length <= 200
  • Every row has the same length.
  • -10^9 <= matrix[i][j] <= 10^9
  • At least one valid split exists.

More ZipRecruiter Online Assessment questions

  • Four-Level Banking System with Scheduled PaymentsOA · Seen Oct 2026
  • Count Three-Digit Numbers with Distinct DigitsOA · Seen Oct 2024
  • Longest Frequency-Bounded SubarrayOA · Seen Oct 2024
  • Minimum Changes to Draw a YOA · Seen Oct 2024
  • Apply Binary State OperationsOA · Seen Sep 2024
  • Simulate Orchard Rot SpreadOA · Seen Sep 2024
  • Compare Odd- and Even-Index SumsOA · Seen Sep 2024
  • Coordinate Removals with Column GravityOA · Seen Sep 2024
  • Lexicographically Smallest End ReversalOA · Seen Sep 2024
  • Recursively Expanded Shell Command CountsOA · Seen Sep 2024

Similar questions at other companies

  • Split a Matrix Into Four Partitions by Average (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
  • Leaves Remaining After Wind GustsOpenAI · OAOpenAI interview questions
  • Shortest Path Around Rectangular ObstaclesDRW · OADRW interview questions
  • Sub-matrix SumsIMC Trading · OAIMC Trading interview questions
  • Largest Sub-GridMathWorks · OAMathWorks interview questions
  • Maximum Trailing Zeros on a Path with at Most One TurnMarshall Wace · OAMarshall Wace interview questions
  • Count L-Shaped PlotsUber · OAUber interview questions
  • Matrix Region SumRippling · OA · ONSITE INTERVIEWRippling interview questions
  • Largest Square Sub-Grid Within a Sum LimitC3.ai · OAC3.ai interview questions
  • Find Minimum Time to Create Beautiful CanvasAmazon · OA

ZipRecruiter interview experiences

  • ZipRecruiter SWE OA, Level Not Reported: 23 Experiences
  • ZipRecruiter SWE Intern OA Scores: 4 Experiences
  • ZipRecruiter SWE New Grad OA: 9 Experiences
All ZipRecruiter interview questionsSee ZipRecruiter hiring insights
Saved
class Solution {
    public int[] findBestPartition(int[][] matrix) {
      // write your code here
    }
}
Checking account…