Skip to content
Y
yTube.SITE v8.0.4
media / worlds / tools / internet oddities
YouTube / video information

LeetCode 1878 | Get Biggest Three Rhombus Sums in a Grid | Java | Medium | Math | CodeByTushu

Video information, playback and saved actions.

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
Β Β Β Β Β Β 
Videos related to "LeetCode 1878 | Get Biggest Three Rhombus Sums in a Grid | Java | Medium | Math | CodeByTushu"

Related videos are temporarily unavailable.

Try again, or come back later.