Get Biggest Three Rhombus Sums in a Grid solution leetcode
Table of Contents
You are given an m x n
integer matrix grid
.
A rhombus sum is the sum of the elements that form the border of a regular rhombus shape in grid
. 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 rhombus sum:
Note that the rhombus can have an area of 0, which is depicted by the purple rhombus in the bottom right corner.
Return the biggest three distinct rhombus sums in the grid
in descending order. If there are less than three distinct values, return all of them.
Get Biggest Three Rhombus Sums in a Grid solution leetcode
Example 1: Get Biggest Three Rhombus Sums in a Grid solution leetcode
Input: 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]] Output: [228,216,211] Explanation: The rhombus shapes for the three biggest distinct rhombus sums are depicted above.  Blue: 20 + 3 + 200 + 5 = 228  Red: 200 + 2 + 10 + 4 = 216  Green: 5 + 200 + 4 + 2 = 211
Example 2: Get Biggest Three Rhombus Sums in a Grid solution leetcode
Input: grid = [[1,2,3],[4,5,6],[7,8,9]] Output: [20,9,8] Explanation: The rhombus shapes for the three biggest distinct rhombus sums are depicted above.  Blue: 4 + 2 + 6 + 8 = 20  Red: 9 (area 0 rhombus in the bottom right corner)  Green: 8 (area 0 rhombus in the bottom middle)
Example 3: Get Biggest Three Rhombus Sums in a Grid solution leetcode
Input: grid = [[7,7,7]] Output: [7] Explanation: All three possible rhombus sums are the same, so return [7].
Get Biggest Three Rhombus Sums in a Grid solution leetcode
Constraints:
m == grid.length
n == grid[i].length
1 <= m, n <= 100
1 <= grid[i][j] <= 10^{5}
SOLUTION
Click here
Important Note

 To provide a better contest and ensure fairness, we listened to LeetCoders’ feedback and put in lots of thoughts behind the updated contest rule. Please check out our new contest rule which covers more scenarios with details explained.
 The penalty time of 5 minutes will be applied for each wrong submission.
 To ensure the fairness of the contest, LeetCode will hide some test cases during the contest. When users submit incorrect submissions, LeetCode will not show the hidden test cases to the users.
 The final rating of this contest will be updated within 5 working days after the contest.
Below actions are deemed contest violations

 :

 One user submitting with multiple accounts during a contest. LCUS (leetcode.com) account and LCCN (leetcodecn.com) account are considered to be separate accounts, even if both accounts belong to the same user.
 Multiple accounts submitting similar code for the same problem.
 Creating unwanted disturbances which interrupt other users’ participation in a contest.
 Disclosing contest solutions in public discuss posts before the end of a contest.


 LeetCode heavily emphasizes on the justice and fairness of our contests. We have absolutely
ZERO TOLERANCE

 for violation behaviors (such as plagiarism, cheating, etc). When a user is deemed violating contest rules, we will apply the following penalties on this user:

 First violation: LeetCoin amount resets to zero and a contest and discuss ban for 1 month.
 Second violation: Permanent account deactivation without appeal.

 Substrings of Size Three with Distinct Characters3
 Minimize Maximum Pair Sum in Array4
 Get Biggest Three Rhombus Sums in a Grid5
 Minimum XOR Sum of Two Arrays
 Furthermore, we encourage all participants to contribute to maintaining the justice and fairness of our contest. Users who submit valid violation report(s) will earn additional LeetCoins:

 For each violating participant, the first 10 users who submit the violation report towards this participant will each earn 20 LeetCoins.
 Each user can earn up to 100 LeetCoins for reporting violations in a contest.
 Users will not be rewarded LeetCoins for reports on LCCN users.