FastPrepBouncing Diagonal Weights
Problems/Bouncing Diagonal Weights

Bouncing Diagonal Weights

Capital One logoCapital One● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Our version is about 95% the same as the reported Capital One task. The number limits are not available.

Special thanks: 🌷 A special thank you to our lovely, amazing frenz for sharing interview updates and helping keep this question up to date! ٩(ˊᗜˋ*)و ♡

You are given a non-empty square integer matrix matrix.

For every starting cell in the leftmost column, trace a path that visits exactly one cell in each column:

  • The path initially moves one row up and one column right.
  • When the path reaches the top row, it changes direction and continues one row down and one column right until it reaches the rightmost column.

The weight of a starting cell is the sum of the matrix values on its path.

For every starting cell, form the pair (weight, leftmost value). Sort all pairs in ascending lexicographic order: first by weight, then by leftmost value when the weights are equal. Return the second value from each sorted pair.

Function

Diagonalweights(matrix: int[][]) → int[]

Examples

Example 1

matrix = [[2, 3, 2], [0, 2, 5], [1, 0, 1]]return = [1, 2, 0]
matrix
012023210252101

The paths starting in rows 0, 1, and 2 have weights 2 + 2 + 1 = 5, 0 + 3 + 5 = 8, and 1 + 2 + 2 = 5.

The corresponding pairs are (5, 2), (8, 0), and (5, 1). After sorting, they are (5, 1), (5, 2), and (8, 0), so the answer is [1, 2, 0].

Example 2

matrix = [[1, 3, 2, 5], [3, 2, 5, 0], [9, 0, 1, 3], [6, 1, 0, 8]]return = [1, 9, 3, 6]
matrix
012301325132502901336108

The four path weights are 1 + 2 + 1 + 8 = 12, 3 + 3 + 5 + 3 = 14, 9 + 2 + 2 + 0 = 13, and 6 + 0 + 5 + 5 = 16.

The sorted pairs are (12, 1), (13, 9), (14, 3), and (16, 6), so the answer is [1, 9, 3, 6].

Constraints

  • matrix is a non-empty square matrix of integers.

More Capital One Online Assessment questions

  • Distinct Values on Maximum-Sum FramesOA · Seen Nov 2026
  • Lowest Number in an Open RangeOA · Seen Nov 2026
  • Branch with the Most FilesOA · Seen Nov 2026
  • Earliest Meeting Time for All EmployeesOA · Seen Nov 2026
  • Earn the Most 🐝OA · Seen Nov 2026
  • Rank Football TeamsOA · Seen Oct 2026
  • Count Subarrays Matching a Comparison PatternOA · Seen Oct 2026
  • Arithmetic Triplets After QueriesOA · Seen Oct 2026
  • Count One-Swap Number PairsOA · Seen Oct 2026
  • Sort Adjacent PairsOA · Seen Oct 2026

Similar questions at other companies

  • Sort Concentric Matrix Borders ClockwiseByteDance · OAByteDance interview questions
  • Sort Concentric Matrix RingsxAI · OAxAI interview questions
  • Fill and Sort Packed Missing-Number GridsZipRecruiter · OAZipRecruiter interview questions
  • Minimum Cost Path with TeleportationsAmazon · OA
  • Best Meeting PointWalmart · OAWalmart interview questions
  • Longest Increasing Path in a MatrixNutanix · OANutanix interview questions
  • Sparse Matrix Addition and MultiplicationPinterest · PHONE SCREENPinterest interview questions
  • Optimal Central WarehouseGoogle · ONSITE INTERVIEWGoogle interview questions
  • Enumerate Character Paths to a MarkerTesla · ONSITE INTERVIEWTesla interview questions
  • Map Black Cells to Covering 2x2 BlocksSquare · PHONE SCREEN

Capital One interview experiences

  • Capital One Coding OA Questions: 3 Experiences
  • Capital One Experienced Engineer Power Day and OA: 6 Experiences
  • Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
  • Capital One TDP Agentic Round (AI Coding): 7 Experiences
  • Capital One SWE Power Day, Level Not Reported: 6 Experiences
  • Capital One TIP Intern OA and Power Day: 13 Experiences
All Capital One interview questionsSee Capital One hiring insights
Saved
class Solution {
    public int[] Diagonalweights(int[][] matrix) {
      // write your code here
    }

}
Checking account…