The Get Biggest Three Rhombus Sums in a Grid interview question gives you a 2D integer matrix. A "rhombus sum" is the sum of all elements that lie on the border of a rhombus shape within the grid. The rhombus can be of any size (including a single cell, which has an area of 0 but a sum equal to its value). You need to find all distinct rhombus sums and return the top three largest ones in descending order. If there are fewer than three distinct sums, return all of them.
Companies like Uber and Capital One ask the Get Biggest Three Rhombus Sums in a Grid coding problem to test your ability to handle complex matrix traversals. It evaluates your spatial reasoning and whether you can iterate over diagonal borders efficiently. It's a "Medium" problem that tests if you can keep track of maximum values (using a heap or sorted set) while exhaustively exploring geometric shapes in a grid.
This problem relies on Matrix Traversal and Prefix Sums (Optional).
(i, j) to treat it as the top vertex of a potential rhombus.k of the rhombus (from 0 up to the boundary limits).grid[i][j]. For size > 0, trace the four diagonal sides.Set to store distinct sums, and keep track of the largest three (or use a Min-Heap of size 3).Grid:
[3, 4, 5]
[2, 7, 1]
[8, 9, 2]
(0, 1) which is 4.
(1, 0) is 2.(1, 2) is 1.(2, 1) is 9.k too far and attempting to access cells outside the grid matrix.[10, 10, 8] instead of [10, 8, 7]).When tracing diagonal borders, it's easy to accidentally double-count the vertices (top, bottom, left, right). Be careful with your loop ranges to ensure each vertex is added exactly once.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Average Height of Buildings in Each Segment | Medium | Solve | |
| Minimum Operations to Make a Uni-Value Grid | Medium | Solve | |
| Best Meeting Point | Hard | Solve | |
| Car Pooling | Medium | Solve | |
| K Highest Ranked Items Within a Price Range | Medium | Solve |