FastPrepDistinct Values in Maximum-Sum Square Windows
Problems/Distinct Values in Maximum-Sum Square Windows

Distinct Values in Maximum-Sum Square Windows

ZipRecruiter logoZipRecruiter● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A ZipRecruiter new-grad OA report describes fixed square windows, the maximum full-window sum, and the distinct values across all tied winners. We supplied limits and a function signature.

Enumerate every size by size submatrix. Find the maximum window sum, collect each distinct value appearing in any tied maximum window, and return their sum.

Function

sumDistinctMaxWindowValues(matrix: int[][], size: int) → long

Examples

Example 1

matrix = [[1,2,1],[2,1,2],[1,2,1]]size = 2return = 3
matrix
012012112122121

All windows tie and the distinct union is {1,2}.

Example 2

matrix = [[1,2],[3,4]]size = 1return = 4
matrix
01012134

The maximum one-cell window contains 4.

Constraints

  • 1 <= rows,columns <= 200
  • 1 <= size <= min(rows,columns)

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

  • Number of Submatrices That Sum to TargetWhatNot · ONSITE INTERVIEWWhatNot interview questions
  • Gaussian Naive Bayes Classifier (Machine Learning OA)Pinterest · OAPinterest interview questions
  • Split a Matrix Into Four Partitions by Average (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
  • Subscription and Usage-Based Billing CalculatorStripe · OAStripe interview questions
  • Count Subarrays with a Perfect-Square ProductMicrosoft · OAMicrosoft interview questions
  • Find a Symbolic Matrix PatternCapital One · OACapital One interview questions
  • Leaves Remaining After Wind GustsOpenAI · OAOpenAI interview questions
  • Shortest Digit Prefix for Target MultisetsVisa · OAVisa interview questions
  • First Completed Mingo LineEpic · OAEpic interview questions
  • Shortest Path Around Rectangular ObstaclesDRW · OADRW interview questions

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 long sumDistinctMaxWindowValues(int[][] matrix, int size) {
        // Write your code here.
    }

}
Checking account…