1878. Get Biggest Three Rhombus Sums in a Grid Medium
1/**
2 * [1878] Get Biggest Three Rhombus Sums in a Grid
3 *
4 * You are given an m x n integer matrix grid.
5 * 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:
6 * <img alt="" src="https://assets.leetcode.com/uploads/2021/04/23/pc73-q4-desc-2.png" style="width: 385px; height: 385px;" />
7 * Note that the rhombus can have an area of 0, which is depicted by the purple rhombus in the bottom right corner.
8 * 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.
9 *
10 * Example 1:
11 * <img alt="" src="https://assets.leetcode.com/uploads/2021/04/23/pc73-q4-ex1.png" style="width: 360px; height: 361px;" />
12 * 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]]
13 * Output: [228,216,211]
14 * Explanation: The rhombus shapes for the three biggest distinct rhombus sums are depicted above.
15 * - Blue: 20 + 3 + 200 + 5 = 228
16 * - Red: 200 + 2 + 10 + 4 = 216
17 * - Green: 5 + 200 + 4 + 2 = 211
18 *
19 * Example 2:
20 * <img alt="" src="https://assets.leetcode.com/uploads/2021/04/23/pc73-q4-ex2.png" style="width: 217px; height: 217px;" />
21 * Input: grid = [[1,2,3],[4,5,6],[7,8,9]]
22 * Output: [20,9,8]
23 * Explanation: The rhombus shapes for the three biggest distinct rhombus sums are depicted above.
24 * - Blue: 4 + 2 + 6 + 8 = 20
25 * - Red: 9 (area 0 rhombus in the bottom right corner)
26 * - Green: 8 (area 0 rhombus in the bottom middle)
27 *
28 * Example 3:
29 *
30 * Input: grid = [[7,7,7]]
31 * Output: [7]
32 * Explanation: All three possible rhombus sums are the same, so return [7].
33 *
34 *
35 * Constraints:
36 *
37 * m == grid.length
38 * n == grid[i].length
39 * 1 <= m, n <= 50
40 * 1 <= grid[i][j] <= 10^5
41 *
42 */
43pub struct Solution {}
44
45// problem: https://leetcode.com/problems/get-biggest-three-rhombus-sums-in-a-grid/
46// discuss: https://leetcode.com/problems/get-biggest-three-rhombus-sums-in-a-grid/discuss/?currentPage=1&orderBy=most_votes&query=
47
48// submission codes start here
49
50impl Solution {
51 pub fn get_biggest_three(grid: Vec<Vec<i32>>) -> Vec<i32> {
52 vec![]
53 }
54}
55
56// submission codes end
57
58#[cfg(test)]
59mod tests {
60 use super::*;
61
62 #[test]
63 fn test_1878() {
64 }
65}
66
Back
© 2025 bowen.ge All Rights Reserved.