Class Solution
java.lang.Object
g1801_1900.s1878_get_biggest_three_rhombus_sums_in_a_grid.Solution
1878 - Get Biggest Three Rhombus Sums in a Grid.<p>Medium</p>
<p>You are given an <code>m x n</code> integer matrix <code>grid</code>.</p>
<p>A <strong>rhombus sum</strong> is the sum of the elements that form <strong>the</strong> <strong>border</strong> of a regular rhombus shape in <code>grid</code>. The rhombus must have the shape of a square rotated 45 degrees with each of the corners centered in a grid cell. Below is an image of four valid rhombus shapes with the corresponding colored cells that should be included in each <strong>rhombus sum</strong>:</p>
<p><img src="https://assets.leetcode.com/uploads/2021/04/23/pc73-q4-desc-2.png" alt="" /></p>
<p>Note that the rhombus can have an area of 0, which is depicted by the purple rhombus in the bottom right corner.</p>
<p>Return <em>the biggest three <strong>distinct rhombus sums</strong> in the</em> <code>grid</code> <em>in <strong>descending order</strong>__. If there are less than three distinct values, return all of them</em>.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/04/23/pc73-q4-ex1.png" alt="" /></p>
<p><strong>Input:</strong> grid = [[3,4,5,1,3],[3,3,4,2,3],[20,30,200,40,10],[1,5,5,4,1],[4,3,2,2,5]]</p>
<p><strong>Output:</strong> [228,216,211]</p>
<p><strong>Explanation:</strong> The rhombus shapes for the three biggest distinct rhombus sums are depicted above.</p>
<ul>
<li>
<p>Blue: 20 + 3 + 200 + 5 = 228</p>
</li>
<li>
<p>Red: 200 + 2 + 10 + 4 = 216</p>
</li>
<li>
<p>Green: 5 + 200 + 4 + 2 = 211</p>
</li>
</ul>
<p><strong>Example 2:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/04/23/pc73-q4-ex2.png" alt="" /></p>
<p><strong>Input:</strong> grid = [[1,2,3],[4,5,6],[7,8,9]]</p>
<p><strong>Output:</strong> [20,9,8]</p>
<p><strong>Explanation:</strong> The rhombus shapes for the three biggest distinct rhombus sums are depicted above.</p>
<ul>
<li>
<p>Blue: 4 + 2 + 6 + 8 = 20</p>
</li>
<li>
<p>Red: 9 (area 0 rhombus in the bottom right corner)</p>
</li>
<li>
<p>Green: 8 (area 0 rhombus in the bottom middle)</p>
</li>
</ul>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> grid = [[7,7,7]]</p>
<p><strong>Output:</strong> [7]</p>
<p><strong>Explanation:</strong> All three possible rhombus sums are the same, so return [7].</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>m == grid.length</code></li>
<li><code>n == grid[i].length</code></li>
<li><code>1 <= m, n <= 50</code></li>
<li><code>1 <= grid[i][j] <= 10<sup>5</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
getBiggestThree
public int[] getBiggestThree(int[][] grid)
-