FastPrepMaximum k-by-k Square Sum
Problems/Maximum k-by-k Square Sum

Maximum k-by-k Square Sum

JP Morgan Chase logoJP Morgan Chase● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a JP Morgan Chase intern online assessment. Two reports describe maximizing a k-by-k square sum, and one says brute force passed. A linked reference confirms the square-matrix operation. We chose the function interface, the limits and the examples. The current reference is not the 2019 wording we could not recover. Our version is about 95% the same as the reported tasks.

You are given a square integer matrix mat and an integer k. Return the greatest sum of any contiguous k x k square inside the matrix.

For this exercise, return the sum as one integer. A square uses k consecutive rows and k consecutive columns and must fit entirely inside the matrix. Negative entries are allowed, and you must choose a square even when every possible sum is negative.

Function

maximumSquareSum(mat: int[][], k: int) → int

Examples

Example 1

mat = [[1,2,3],[4,5,6],[7,8,9]]k = 2return = 28
mat
012012314562789

The bottom-right 2-by-2 square contains 5,6,8,9 and sums to 28. The other square sums are 12,16 and 24.

Example 2

mat = [[-5,-2],[-3,-4]]k = 1return = -2
mat
010-5-21-3-4

A 1-by-1 square is one cell. The greatest cell value is -2; choosing an empty square is not allowed.

Constraints

  • 1 <= mat.length <= 50.
  • 1 <= mat[i].length <= 50, and every row has exactly mat.length entries.
  • -10000 <= mat[i][j] <= 10000.
  • 1 <= k <= mat.length.

More JP Morgan Chase Online Assessment questions

  • Find Total CostOA · Seen Oct 2026
  • Minimum Meeting RoomsOA · Seen Oct 2026
  • Count Dropped RequestsOA · Seen Oct 2026
  • Maximize Minimum Deployment DifficultyOA · Seen Oct 2026
  • Task SchedulingOA · Seen Oct 2026
  • Substring RemovalOA · Seen Oct 2026
  • Maximum Game Board ScoreOA · Seen Sep 2026
  • Minimum Digit Changes Between String HalvesOA · Seen Sep 2026
  • Same Substring Within BudgetOA · Seen Sep 2026
  • Invert Ad Visibility BitsOA · Seen Aug 2026

Similar questions at other companies

  • Most Visited Sprint MarkerMicrosoft · OAMicrosoft interview questions
  • Earliest Time to Schedule a MeetingMathWorks · OAMathWorks interview questions
  • Earliest Meeting Start on a 24-Hour ClockIMC Trading · OAIMC Trading interview questions
  • Calculate the Sum After Range TogglesBlink Health · OA
  • Optimal TransferSnowflake · OASnowflake interview questions
  • Count Attack Vectors by Divisor RangeVisa · OAVisa interview questions
  • Smallest Most-Lit Street PositionHudson River Trading · OAHudson River Trading interview questions
  • Most Visited Sprint MarkerChubb · OAChubb interview questions
  • Minimum Seats for One-Way Car PoolingSquadStack.ai · OA
  • Shortest Path Around Rectangular ObstaclesDRW · OADRW interview questions

Interview reports that mention this question

  • JPMorgan Chase Intern Campus Rounds: 4 Experiences (Part 2 of 5)

JP Morgan Chase interview experiences

  • JPMorgan Quant Stats Superdays: 3 Experiences (Part 3 of 3)
  • JPMorgan Quant Modeling Superdays: 7 Experiences (Part 2 of 3)
  • JPMorgan Quant Intern Superday: 19 Experiences (Part 1 of 3)
  • JP Morgan Chase Data and AI Intern Superday: 11 Experiences
  • JPMorgan Code for Good India 2024: 6 Experiences (Part 5 of 5)
All JP Morgan Chase interview questionsSee JP Morgan Chase hiring insights
Saved
class Solution {
    public int maximumSquareSum(int[][] mat, int k) {
        // Write your code here.
    }
}
Checking account…