Reported September 2026
Capital Oneprefix sum

Distinct Values on Maximum-Sum Frames

Reported by candidates from Capital One's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Capital One OA. Under 2s to a working solution.
Founder's read

Capital One reported this one in September 2026, and the whole thing hinges on a hash set plus a fast way to total a border. You're given a matrix and a frameSize, and you have to find the max border sum across every frameSize x frameSize window. Then you collect the distinct values from every tied winner and add them up. It reads like a matrix problem, but the real work is bookkeeping. If you've got an OA invite for this, expect to write it clean and fast. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment.

The problem

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 = 2
return = 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 = 2
return = 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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is computing each border sum in O(1). Build row prefix sums and column prefix sums, then a frame's border is top row segment + bottom row segment + left column segment + right column segment, minus the corners you double counted (when frameSize is greater than 1). With 200 x 200, that's about 40,000 frames, which is easy. Pass one finds the max. Pass two revisits frames that tie and adds their border values into a hash set. Walking each border costs O(frameSize), so worst case is around 200^3 = 8 million, which is fine. Pitfalls: frameSize 1, where the border is a single cell and you must not subtract corners. Also use 64-bit for sums. Don't add values to the set from non-winning frames. If you freeze on the prefix-sum corner math during the live OA, StealthCoder can hand you the working version.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Distinct Values on Maximum-Sum Frames cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Capital One's OA.

Capital One reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Distinct Values on Maximum-Sum Frames FAQ

What's the core trick in Distinct Values on Maximum-Sum Frames?+

Use prefix sums on rows and columns so each border sum is O(1). Track the max, then collect border values from every frame that ties it into a hash set. Sum the set at the end. The distinct part is what makes the set necessary.

How do I handle frameSize equal to 1?+

The border is just one cell. Your formula of four edges minus corners would break, because top, bottom, left, and right all point to the same cell. Special-case it: the sum is the cell value, and the set gets that one value.

Do I need two passes over the matrix?+

Yes, the simplest approach is two passes. First compute the max border sum over all frames. Then go back, and for each frame matching that max, insert its border cells into a set. Doing it in one pass is possible by resetting the set when a new max appears, but it's easier to get wrong.

Will brute force pass at 200 x 200?+

Walking every border directly is about 40,000 frames times up to 800 cells, so roughly 32 million operations. That's likely fine, but prefix sums for the comparison pass are cleaner. Only walk borders fully for tied frames when collecting values.

How should I prepare for this in 48 hours?+

Practice 2D and 1D prefix sums, and writing a hash set over matrix cells. Test on the two examples, especially the all-ties case with {0,1}. Watch for integer overflow, since the result needs a 64-bit type. Skip fancy structures, nothing here needs them.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Capital One.

OA at Capital One?
Invisible during screen share
Get it