Sliding Window Maximum in a Matrix
Updated
Problem statement
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]]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]]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]]The only window is the whole matrix, and its largest value is -2.
Constraints
m == matrix.lengthn == matrix[i].length1 <= m, n <= 300-104 <= matrix[i][j] <= 1041 <= 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