Pop Diagonal Chains
Updated
Problem statement
You are given an m x n integer grid grid and a list moves, where moves[k] = [r, c] names the cell in row r and column c. Rows and columns are numbered from 0. A cell that holds 0 is empty.
Apply the moves one by one, in order. For a move at (r, c):
- If the cell is empty, nothing happens.
- Otherwise, let
vbe its value. The cell pops. Then, starting from(r, c), go in each of the four diagonal directions: up-left, up-right, down-left and down-right. In each direction, step one cell at a time. While the next cell is inside the grid and holdsv, it pops too. Stop at the first cell that is outside the grid or holds a different value. An empty cell also stops the chain. - Every popped cell becomes
0. Nothing falls or moves into the empty cells.
Cells that touch (r, c) only by a side never pop. Return the grid after all moves.
Function
popDiagonalChains(grid: int[][], moves: int[][]) → int[][]Examples
Example 1
grid = [[1,2,1],[2,1,2],[1,2,1]]moves = [[1,1]]return = [[0,2,0],[2,0,2],[0,2,0]]The move pops the 1 in the center. All four corners hold 1 and each sits right next to the center on a diagonal, so they pop too. The 2s touch the center only by a side, so they stay.
Example 2
grid = [[2,7,7,8],[7,2,8,7],[7,7,5,7],[8,7,7,2]]moves = [[0,0],[0,3]]return = [[0,7,7,0],[7,0,0,7],[7,7,5,7],[8,7,7,2]]The first move pops the 2 at (0, 0). Going down and right, (1, 1) is also 2 and pops, but (2, 2) is 5, so the chain stops there. The 2 at (3, 3) stays, because the 5 breaks the chain. The second move pops the 8 at (0, 3). Going down and left, (1, 2) is 8 and pops, then (2, 1) is 7, so the chain stops and the 8 at (3, 0) stays.
Example 3
grid = [[4,4],[4,4]]moves = [[0,0],[1,1],[0,1]]return = [[0,0],[0,0]]The first move pops (0, 0) and its diagonal neighbor (1, 1), giving [[0,4],[4,0]]. Nothing falls into the empty cells. The second move is on an empty cell, so nothing happens. The third move pops (0, 1) and its diagonal neighbor (1, 0), so every cell is 0.
Constraints
1 <= m, n <= 50, wheremis the number of rows andnis the number of columns ofgrid1 <= grid[i][j] <= 91 <= moves.length <= 1000moves[k].length == 20 <= moves[k][0] < mand0 <= moves[k][1] < n- Every row of
gridhas the same length.
More Capital One Online Assessment questions
- 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
- Distinct Values on Maximum-Sum FramesOA · Seen Oct 2026
- Sort Adjacent PairsOA · Seen Oct 2026
- Bouncing Diagonal WeightsOA · Seen Oct 2026
Similar questions at other companies
- Maximum Diamond SumHudson River Trading · OAHudson River Trading interview questions
- Robot Navigation Around LasersRoblox · OARoblox interview questions
- Apply a Reversi MoveAmazon · OA
- Flip, Invert, and Smooth a Binary ImageAbridge · OAAbridge interview questions
- First Completed Mingo LineEpic · OAEpic interview questions
- Rotate a Square Matrix ClockwiseVisa · OAVisa interview questions
- Sort Concentric Matrix Borders ClockwiseByteDance · OAByteDance interview questions
- Sparse Valid Conv2D From ScratchNVIDIA · OANVIDIA interview questions
- Rotate the Box and Drop the StonesZipRecruiter · OAZipRecruiter interview questions
- 2048 Move SimulatorBenchling · OABenchling interview questions
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