<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>
<img alt="" src="https://assets.leetcode.com/uploads/2021/04/23/pc73-q4-desc-2.png" style="width: 385px; height: 385px;" />
<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></em><em>. If there are less than three distinct values, return all of them</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/04/23/pc73-q4-ex1.png" style="width: 360px; height: 361px;" />
<pre>
<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]]
<strong>Output:</strong> [228,216,211]
<strong>Explanation:</strong> 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
</pre>

<p><strong class="example">Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/04/23/pc73-q4-ex2.png" style="width: 217px; height: 217px;" />
<pre>
<strong>Input:</strong> grid = [[1,2,3],[4,5,6],[7,8,9]]
<strong>Output:</strong> [20,9,8]
<strong>Explanation:</strong> 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)
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> grid = [[7,7,7]]
<strong>Output:</strong> [7]
<strong>Explanation:</strong> All three possible rhombus sums are the same, so return [7].
</pre>

<p>&nbsp;</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 &lt;= m, n &lt;= 50</code></li>
	<li><code>1 &lt;= grid[i][j] &lt;= 10<sup>5</sup></code></li>
</ul>

import heapq

class Solution:
    def checkBounds(self, grid, temp):
        m = len(grid)
        n = len(grid[0])
        for i in range(len(temp)):
            if temp[i][0] < 0 or temp[i][0] >= m or temp[i][1] < 0 or temp[i][1] >= n:
                return False

        return True

    def getAllVertices(self, grid, temp, c, delta):
        aP = (c[0]-delta, c[1])
        bP = (c[0], c[1]+delta)
        cP = (c[0]+delta, c[1])
        dP = (c[0], c[1]-delta)

        temp.append(aP)
        temp.append(bP)
        temp.append(cP)
        temp.append(dP)

        if self.checkBounds(grid, temp):
            return True
        return False

    def getAllSum(self, grid, cx, cy, mh):
        # push rh sum of rh with area 0
        heapq.heappush(mh, -grid[cx][cy])
        delta = 1

        while self.getAllVertices(grid, [], (cx, cy), delta):
            a = (cx-delta, cy)
            b = (cx, cy+delta)
            c = (cx+delta, cy)
            d = (cx, cy-delta)

            cSum = grid[a[0]][a[1]] + grid[b[0]][b[1]] + grid[c[0]][c[1]] + grid[d[0]][d[1]]

            # all cells between a and b.
            for i in range(1, delta):
                cSum += grid[a[0]+i][a[1]+i]

            # all cells between b and c.
            for i in range(1, delta):
                cSum += grid[b[0]+i][b[1]-i]

            # all cells between c and d.
            for i in range(1, delta):
                cSum += grid[c[0]-i][c[1]-i]

            # all cells between d and a.
            for i in range(1, delta):
                cSum += grid[d[0]-i][d[1]+i]

            heapq.heappush(mh, -cSum)
            delta += 1

    def getBiggestThree(self, grid: List[List[int]]) -> List[int]:
        ans = []
        max_heap = []
        m = len(grid)
        n = len(grid[0])

        for i in range(m):
            for j in range(n):
                self.getAllSum(grid, i, j, max_heap)

        ans = []
        print (max_heap)
        while max_heap and len(ans) < 3:
            top = -heapq.heappop(max_heap)
            if top not in ans:
                ans.append(top)

        return ans
19400