LeetCode 1878 | Get Biggest Three Rhombus Sums in a Grid | Java | Medium | Math | CodeByTushu
Description: π Welcome Back to CodeByTushu!
In todayβs video, we solve LeetCode 1878 β Get Biggest Three Rhombus Sums in a Grid using Matrix Traversal and Math in Java.
The problem asks us to find the top three largest distinct rhombus border sums in an m by n grid. A rhombus can have an area of zero, which represents an individual grid cell, or an area greater than zero, which forms a square rotated 45 degrees centered in a grid cell. Because the grid dimensions are at most 50 by 50, every potential center and valid radius can be exhaustively evaluated without exceeding the time limit.
For every valid center and radius, we traverse its four diagonal boundary edges in a single unified loop of 4L steps, visiting each border cell exactly once without double counting corners. All computed sums are stored into a balanced tree set to ensure automatic uniqueness. Finally, we extract up to the top three largest distinct sums in descending order, achieving an optimal runtime of well under 10 milliseconds.
π₯ Problem Highlights
β Complete geometric boundary decomposition for area 0 and area greater than 0 rhombuses
β Four symmetric perimeter edges traversed simultaneously to eliminate corner duplication
β Automatic deduplication of identical rhombus sums using a balanced search tree
β Strict matrix boundary validation preventing out-of-bounds indexing
β Seamless handling of edge cases where fewer than three distinct sums exist
β High-performance implementation executing well under 10 milliseconds
β±οΈ TIMESTAMPS
00:00 Intro & Daily Challenge Overview
01:23 Problem Understanding & Rhombus Geometry
03:04 Key Insights: Center Search & Perimeter Traversal
05:42 Algorithmic Strategy & 4-Step Implementation
07:25 Clean Java Solution Walkthrough Line by Line
08:41 Test Cases Walkthrough & Step-by-Step Simulation
10:13 Time Complexity Analysis (O(MΒ·NΒ·minΒ²) - 12 ms)
11:17 Space Complexity Analysis (O(MΒ·NΒ·min) - Minimal Heap)
11:57 Outro & Resources
π Problem Folder & Detailed Documentation:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/tree/main/solutions/March/16-March/1878-Get-Biggest-Three-Rhombus-Sums-in-a-Grid
β Java Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/March/16-March/1878-Get-Biggest-Three-Rhombus-Sums-in-a-Grid/Solution.java
π Python Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/March/16-March/1878-Get-Biggest-Three-Rhombus-Sums-in-a-Grid/solution.py
β‘ C++ Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/March/16-March/1878-Get-Biggest-Three-Rhombus-Sums-in-a-Grid/solution.cpp
π JavaScript Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/March/16-March/1878-Get-Biggest-Three-Rhombus-Sums-in-a-Grid/solution.js
π LeetCode Source Code
π Admin type the link
π All LeetCode Solutions
π https://codebytushu.com/Leetcode/
π± Join CodeByTushu on WhatsApp
Get coding updates, LeetCode solutions, daily questions and more.
https://whatsapp.com/channel/0029Vb8k5mCDeON2Xwlkxe40
β€οΈ Donate
π https://codebytushu.com/Leetcode/donate.php
π₯ Perfect For
LeetCode Medium Problems
Java DSA Preparation
Matrix and 2D Grid Algorithms
Geometry and Boundary Traversal
Set Deduplication Techniques
Time Complexity Optimization
Coding Interview Preparation
Problem Solving
π Follow CodeByTushu
βΆοΈ YouTube: https://www.youtube.com/@codebytushu
πΈ Instagram: https://instagram.com/codebytushu/
πΌ LinkedIn: https://www.linkedin.com/company/codebytushu/
π Website: https://codebytushu.com
π GitHub: https://github.com/CodeByTushu
β€οΈ Donβt Forget To
π Like | π¬ Comment | π Subscribe
π¬ Question of the Day
For a regular rhombus with radius L greater than 0 centered at (r, c), how many grid cells make up its outer border?
1οΈβ£ 2 * L
2οΈβ£ 4 * L
3οΈβ£ 4 * L + 1
4οΈβ£ 2 * L * L
#LeetCode1878 #LeetCode #GetBiggestThreeRhombusSumsInAGrid #Java #JavaDSA #Matrix #Array #DSA #CodingInterview #ProblemSolving #LeetCodeMedium #DailyLeetCode #JavaProgramming #CodeByTushu
π Comment the answer below! π₯Β Close description
In todayβs video, we solve LeetCode 1878 β Get Biggest Three Rhombus Sums in a Grid using Matrix Traversal and Math in Java.
The problem asks us to find the top three largest distinct rhombus border sums in an m by n grid. A rhombus can have an area of zero, which represents an individual grid cell, or an area greater than zero, which forms a square rotated 45 degrees centered in a grid cell. Because the grid dimensions are at most 50 by 50, every potential center and valid radius can be exhaustively evaluated without exceeding the time limit.
For every valid center and radius, we traverse its four diagonal boundary edges in a single unified loop of 4L steps, visiting each border cell exactly once without double counting corners. All computed sums are stored into a balanced tree set to ensure automatic uniqueness. Finally, we extract up to the top three largest distinct sums in descending order, achieving an optimal runtime of well under 10 milliseconds.
π₯ Problem Highlights
β Complete geometric boundary decomposition for area 0 and area greater than 0 rhombuses
β Four symmetric perimeter edges traversed simultaneously to eliminate corner duplication
β Automatic deduplication of identical rhombus sums using a balanced search tree
β Strict matrix boundary validation preventing out-of-bounds indexing
β Seamless handling of edge cases where fewer than three distinct sums exist
β High-performance implementation executing well under 10 milliseconds
β±οΈ TIMESTAMPS
00:00 Intro & Daily Challenge Overview
01:23 Problem Understanding & Rhombus Geometry
03:04 Key Insights: Center Search & Perimeter Traversal
05:42 Algorithmic Strategy & 4-Step Implementation
07:25 Clean Java Solution Walkthrough Line by Line
08:41 Test Cases Walkthrough & Step-by-Step Simulation
10:13 Time Complexity Analysis (O(MΒ·NΒ·minΒ²) - 12 ms)
11:17 Space Complexity Analysis (O(MΒ·NΒ·min) - Minimal Heap)
11:57 Outro & Resources
π Problem Folder & Detailed Documentation:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/tree/main/solutions/March/16-March/1878-Get-Biggest-Three-Rhombus-Sums-in-a-Grid
β Java Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/March/16-March/1878-Get-Biggest-Three-Rhombus-Sums-in-a-Grid/Solution.java
π Python Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/March/16-March/1878-Get-Biggest-Three-Rhombus-Sums-in-a-Grid/solution.py
β‘ C++ Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/March/16-March/1878-Get-Biggest-Three-Rhombus-Sums-in-a-Grid/solution.cpp
π JavaScript Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/March/16-March/1878-Get-Biggest-Three-Rhombus-Sums-in-a-Grid/solution.js
π LeetCode Source Code
π Admin type the link
π All LeetCode Solutions
π https://codebytushu.com/Leetcode/
π± Join CodeByTushu on WhatsApp
Get coding updates, LeetCode solutions, daily questions and more.
https://whatsapp.com/channel/0029Vb8k5mCDeON2Xwlkxe40
β€οΈ Donate
π https://codebytushu.com/Leetcode/donate.php
π₯ Perfect For
LeetCode Medium Problems
Java DSA Preparation
Matrix and 2D Grid Algorithms
Geometry and Boundary Traversal
Set Deduplication Techniques
Time Complexity Optimization
Coding Interview Preparation
Problem Solving
π Follow CodeByTushu
βΆοΈ YouTube: https://www.youtube.com/@codebytushu
πΈ Instagram: https://instagram.com/codebytushu/
πΌ LinkedIn: https://www.linkedin.com/company/codebytushu/
π Website: https://codebytushu.com
π GitHub: https://github.com/CodeByTushu
β€οΈ Donβt Forget To
π Like | π¬ Comment | π Subscribe
π¬ Question of the Day
For a regular rhombus with radius L greater than 0 centered at (r, c), how many grid cells make up its outer border?
1οΈβ£ 2 * L
2οΈβ£ 4 * L
3οΈβ£ 4 * L + 1
4οΈβ£ 2 * L * L
#LeetCode1878 #LeetCode #GetBiggestThreeRhombusSumsInAGrid #Java #JavaDSA #Matrix #Array #DSA #CodingInterview #ProblemSolving #LeetCodeMedium #DailyLeetCode #JavaProgramming #CodeByTushu
π Comment the answer below! π₯Β Close description
