FastPrepSliding Window Maximum in a Matrix
Problems/Sliding Window Maximum in a Matrix

Sliding Window Maximum in a Matrix

Citadel logoCitadel● HardINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Citadel Securities online assessment for a software engineering internship in New York, as one of two problems where speed mattered. The candidate described a sliding window problem set in a matrix and compared it to the well-known task of finding the largest value in every window of an array.

The account gives no statement, examples or limits. Here, the windows are k by k squares and you return the largest value of each one, laid out by the window's top-left corner. The limits (at most 300 rows and columns, values from -10^4 to 10^4) and the examples are ours.

Our version is about 60% the same as the reported question.

You are given an m x n integer matrix matrix and an integer k. A window is a k x k square of cells inside the matrix. The window whose top-left cell is (i, j) covers rows i to i + k - 1 and columns j to j + k - 1.

Return the (m - k + 1) x (n - k + 1) matrix result, where result[i][j] is the largest value in the window whose top-left cell is (i, j).

Function

maxSlidingWindow(matrix: int[][], k: int) → int[][]

Examples

Example 1

matrix = [[1,3,-1,2],[4,0,5,-2],[2,6,1,3]]k = 2return = [[4,5,5],[6,6,5]]
matrix
0123013-121405-222613
→
return
01204551665

There are 2 x 3 windows of size 2 x 2. The window with top-left cell (0, 0) holds 1, 3, 4 and 0, so its largest value is 4. The window with top-left cell (1, 1) holds 0, 5, 6 and 1, so its largest value is 6. The other four windows give 5, 5, 6 and 5.

Example 2

matrix = [[7,-3,2],[0,9,-8]]k = 2return = [[9,9]]
matrix
01207-32109-8
→
return
01099

The matrix has 2 rows, so there is one row of windows. The window starting at column 0 holds 7, -3, 0 and 9. The window starting at column 1 holds -3, 2, 9 and -8. Both contain 9.

Example 3

matrix = [[-4,-2],[-6,-9]]k = 2return = [[-2]]
matrix
010-4-21-6-9
→
return
00-2

The only window is the whole matrix, and its largest value is -2.

Constraints

  • m == matrix.length
  • n == matrix[i].length
  • 1 <= m, n <= 300
  • -104 <= matrix[i][j] <= 104
  • 1 <= k <= min(m, n)

More Citadel Online Assessment questions

  • Speed Up a Slow FunctionOA · PHONE SCREEN · Seen Nov 2026
  • Possible MEX Values After One Optional IncrementOA · Seen Oct 2026
  • Busy IntersectionOA · Seen Sep 2026
  • Shortest Path in an Unweighted GraphOA · Seen Sep 2026
  • Maximize Workday EarningsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Minimum Changes for Palindromic BlocksOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Minimum Image Processing CostOA · Seen Jul 2026
  • Coprime Pick with Change CostOA · Seen Jul 2026
  • Process SchedulingOA · Seen Mar 2026
  • Employee With the Most OverlapsOA · Seen Feb 2026

Similar questions at other companies

  • Incident MonitorStripe · OAStripe interview questions
  • Minimum of Fixed-Window MaximaJuspay · OA
  • Maximum of Subarray MinimumsJP Morgan Chase · OAJP Morgan Chase interview questions
  • Profit AnalysisVirtu Financial · OAVirtu Financial interview questions
  • Most Negative Number in Each WindowWells Fargo · OAWells Fargo interview questions
  • Maximum of Fixed-Window MinimaRoblox · OARoblox interview questions
  • Shortest Subarray with Sum at Least KOracle · ONSITE INTERVIEWOracle interview questions
  • Sliding Window MaximumGroww · PHONE SCREEN
  • Sliding Window MaximumAmazon · ONSITE INTERVIEW
  • Largest Value in Every Sliding WindowAdobe · PHONE SCREENAdobe interview questions

Citadel interview experiences

  • Citadel Securities Quant Researcher Intern Loop: 1 Experience
  • Citadel Securities Research Engineer Interview: 1 Experience
  • Citadel Securities SWE Intern First Round: 2 Experiences
  • Citadel Securities Experienced SWE Interviews: 1 Experience
  • Citadel SWE Intern Later Rounds and Superday: 13 Experiences
  • Citadel SWE Intern First-Round Questions: 20 Experiences
All Citadel interview questionsSee Citadel hiring insights
Saved
class Solution {
    public int[][] maxSlidingWindow(int[][] matrix, int k) {
      // Write your code here.
    }
}
Checking account…