Maximum Diamond Sum
Updated
Problem statement
You are given an integer matrix grid and a list diamonds. Each diamond is [row, column, radius] and contains every cell whose Manhattan distance from its center is at most radius.
Only diamonds fully contained in the matrix are listed. Return the maximum sum of the cells in any listed diamond.
Function
maximumDiamondSum(grid: int[][], diamonds: int[][]) → longExamples
Example 1
grid = [[1,2,3],[4,5,6],[7,8,9]]diamonds = [[1,1,1],[1,1,0]]return = 25The radius-one diamond contains 2, 4, 5, 6, and 8, whose sum is 25.
Example 2
grid = [[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1]]diamonds = [[2,2,2],[1,1,1]]return = 13The radius-two diamond has thirteen cells, more than the five-cell alternative.
Example 3
grid = [[-5,-1,-5],[-1,10,-1],[-5,-1,-5]]diamonds = [[1,1,1],[1,1,0]]return = 10The center-only diamond is better because the surrounding values reduce the larger diamond's sum.
Constraints
1 <= grid.length, grid[0].length <= 200.- The matrix is rectangular and
-10^6 <= grid[r][c] <= 10^6. 1 <= diamonds.length <= 10000.- Every diamond has nonnegative radius and is fully contained in the matrix.
- The total number of cells across all listed diamonds is at most
10^6.
More Hudson River Trading Online Assessment questions
- Count Palindrome Addition ChoicesOA · Seen Nov 2026
- Count Multiples of Three with Two SevensOA · Seen Oct 2026
- Recursively Expanded Shell Command CountsOA · Seen Oct 2026
- Rotate Matrix Regions Around the DiagonalsOA · Seen Oct 2026
- Smallest Most-Lit Street PositionOA · Seen Oct 2026
- Rearrange String by Alternating EndsOA · Seen Sep 2026
- Most Items Within Budget from a Start IndexOA · Seen Sep 2026
- Count Fancy NumbersOA · Seen Sep 2026
- Count Pieces After Othello MovesOA · Seen Sep 2026
- Merge Row Trees by Key PathOA · Seen Sep 2026
Similar questions at other companies
- 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
- Apply Matrix OperationsCapital One · OACapital One interview questions
- Rotate the Box and Drop the StonesZipRecruiter · OAZipRecruiter interview questions
- 2048 Move SimulatorBenchling · OABenchling interview questions