FastPrepDistinct Values on Maximum-Sum Frames
Problems/Distinct Values on Maximum-Sum Frames

Distinct Values on Maximum-Sum Frames

Capital One logoCapital One● MediumFULLTIMEOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report establishes the task identity and central capability. This practice contract supplies only the portable interface, deterministic boundary rules, and output serialization needed for consistent execution.

Given an integer matrix and frameSize, consider every contiguous frameSize × frameSize submatrix. Its border contains each cell on its top row, bottom row, left column, or right column exactly once.

Find the maximum border sum. Among every frame tied for that maximum, collect all integer values that occur on a winning border. Return the sum of those distinct values.

Function

sumDistinctWinningBorderValues(matrix: int[][], frameSize: int) → long

Examples

Example 1

matrix = [[1,2,3],[4,5,6],[7,8,9]]frameSize = 2return = 28

The bottom-right 2-by-2 frame has the unique maximum border sum, and 5+6+8+9=28.

Example 2

matrix = [[1,1,1],[1,0,1],[1,1,1]]frameSize = 2return = 1

All four frames tie; the union of their border values is {0,1}.

Constraints

  • 1 <= rows, columns <= 200.
  • 1 <= frameSize <= min(rows, columns).
  • Matrix values fit in a 32-bit signed integer; the result fits in a 64-bit signed integer.

More Capital One problems

  • Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
  • Rank Football TeamsOA · Seen Oct 2026
  • Count Subarrays Matching a Comparison PatternOA · Seen Oct 2026
All Capital One interview questionsSee Capital One hiring insights
Saved
class Solution {
    public long sumDistinctWinningBorderValues(int[][] matrix, int frameSize) {
      // write your code here
    }
}
Checking account…