FastPrepCentered K-by-K Submatrix Sums
Problems/Centered K-by-K Submatrix Sums

Centered K-by-K Submatrix Sums

Citadel logoCitadel● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Citadel intern onsite interview. The report asks for one k-by-k submatrix sum for each cell and names two-dimensional prefix sums. It leaves out how the window lines up, what happens at the edges, the function interface, the examples, and the limits. Our version is about 80% the same as the reported question.

You are given a non-empty integer matrix matrix and a positive odd integer k. Construct an output matrix with the same dimensions.

Let radius = (k - 1) / 2. For every cell (row, col), sum all input cells inside the centered k-by-k window:

row - radius <= i <= row + radius
col - radius <= j <= col + radius

Clip the window to valid matrix coordinates. Return the per-cell sums using signed 64-bit integers.

Function

centeredSubmatrixSums(matrix: int[][], k: int) → long[][]

Examples

Example 1

matrix = [[1,2,3],[4,5,6],[7,8,9]]k = 3return = [[12,21,16],[27,45,33],[24,39,28]]
matrix
012012314562789
→
return
012012211612745332243928
Moved or new

The center cell sees the whole matrix and has sum 45. The top-left cell sees only [[1,2],[4,5]], whose sum is 12.

Example 2

matrix = [[2,-1,4],[0,3,5]]k = 1return = [[2,-1,4],[0,3,5]]
matrix
01202-141035
→
return
01202-141035

When k = 1, each centered window contains only its own cell.

Example 3

matrix = [[1,2,3],[4,5,6]]k = 5return = [[21,21,21],[21,21,21]]
matrix
01201231456
→
return
01202121211212121
Moved or new

The radius is 2, so after clipping, every window covers the complete matrix and has sum 21.

Constraints

  • 1 <= matrix.length, matrix[0].length <= 1000.
  • k is positive and odd.
  • 1 <= k <= 2 * max(matrix.length, matrix[0].length) + 1.
  • -10^9 <= matrix[row][col] <= 10^9.
  • Every output sum fits in a signed 64-bit integer.

More Citadel Onsite Interview questions

  • Maximize Workday EarningsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Minimum Changes for Palindromic BlocksOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Removal PoolONSITE INTERVIEW · Seen Sep 2026
  • Search Suggestions with a Prefix TreeONSITE INTERVIEW · Seen Aug 2026
  • Traverse Interior Matrix Cells in Row-Major OrderONSITE INTERVIEW · Seen Aug 2026
  • Limit Order Book Matching EnginePHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Fixed-Capacity Circular BufferONSITE INTERVIEW · Seen Jun 2026
  • Stock Trading with a Fee and a CooldownONSITE INTERVIEW · Seen May 2026
  • Time-Based Key-Value StorePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2026
  • 2048 Simulation and Board CodecONSITE INTERVIEW · Seen Jan 2026

Similar questions at other companies

  • Range Sum Queries on a Fixed GridGoogle · ONSITE INTERVIEWGoogle interview questions
  • Restaurant Delivery HeatmapDoorDash · ONSITE INTERVIEWDoorDash interview questions
  • Number of Submatrices That Sum to TargetWhatNot · ONSITE INTERVIEWWhatNot interview questions
  • Split a Matrix Into Four Partitions by Average (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
  • Shortest Path Around Rectangular ObstaclesDRW · OADRW interview questions
  • Sub-Matrix Sum QueriesHudson River Trading · OAHudson River Trading interview questions
  • Largest Square Sub-Grid Within a Sum LimitC3.ai · OAC3.ai interview questions
  • Matrix Region and Ring SumsNVIDIA · PHONE SCREENNVIDIA interview questions
  • Count Non-Overlapping Pairs of Rectangles That Sum to KWisdomAI · PHONE SCREEN
  • Maximum Sum RectangleDeloitte · OADeloitte interview questions

Interview reports that mention this question

  • Citadel SWE Intern First-Round Questions: 20 Experiences

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
All Citadel interview questionsSee Citadel hiring insights
Saved
class Solution {
    public long[][] centeredSubmatrixSums(int[][] matrix, int k) {
      // write your code here
    }
}
Checking account…