Rectangle Overlap | LEETCODE 836 | Solve In Seconds | Amazon Most Asked Interview |

# leetcode# java# python# cpp
Rectangle Overlap | LEETCODE 836 | Solve In Seconds | Amazon Most Asked Interview |Shaan Yadav

Rectangle Overlap | LEETCODE 836 | Solve In Seconds | Amazon Most Asked Interview | 🔔 Love...

Rectangle Overlap | LEETCODE 836 | Solve In Seconds | Amazon Most Asked Interview |

🔔 Love FAANG-style LeetCode walkthroughs? Don't solve alone — join 2,000+ coders getting daily breakdowns (Telegram is fastest):

Rectangle Overlap LeetCode 836 cracked with best visualization in just three lines — Amazon Adobe Meta Docusign interview favorite with O(1) width and height logic made instantly clear.

LeetCode Question: https://leetcode.com/problems/rectangle-overlap/
Solution (Java / Python / C++ / C): https://github.com/Shaanworkspace/YOUTUBE-DRIVE/blob/main/Leetcode_Daily/LC_836_Rectangle_Overlap_All_Languages.md

Rectangle Overlap LeetCode 836 gives you two rectangles as rec1 equals x1 y1 x2 y2 and rec2 equals x1 y1 x2 y2. Each rectangle uses only two diagonal points — bottom-left x1 y1 and top-right x2 y2. Draw lines through those points and you get all four sides. The task is whether the common overlapping area is strictly greater than zero. Edge or corner touching returns false, separate rectangles return false, only positive width and positive height together return true. This video makes that definition fully visual, then solves it in O(1) time and O(1) space with the common width and height projection trick asked at Amazon, Adobe, Meta Facebook and Docusign.

Every part of the video is mapped to chapters. We define rectangles, decode the array input, visualize the three cases, plot a full example, derive common width as min of right edges minus max of left edges, derive common height the same way on Y, show why multiplying to area fails when both are negative, and fix it by checking width greater than zero and height greater than zero directly. The three-line Java code is typed, run on samples and submitted to pass all tests. Code in Java, Python, C++ and C is linked above.

00:00 — Why Visualizing Rectangle Overlap Makes It Easy
Three lines become obvious once you see rectangles as projections — a picture beats memorizing formulas.

01:00 — How Two Points Define Any Rectangle
x1 y1 bottom-left and x2 y2 top-right — four lines through them build the full rectangle and explain rec1 rec2 input.

02:15 — True Overlap Needs Positive Common Area
Overlap needs strictly positive common area — touching at an edge with zero area returns false.

03:05 — Overlap Versus Touching Versus Separate Cases
Case one positive area, case two shares only boundary, case three completely separate — see all three side by side.

04:50 — Grid Example Walkthrough Step By Step
Plot rec1 0 0 to 4 4 and rec2 2 2 to 6 5 on one grid and shade the intersecting rectangle.

06:15 — Finding Common Width With Min Max Formula
Common width equals min of x2 minus max of x1 — project both intervals on X and take the overlap length.

07:50 — Finding Common Height Same Trick On Y Axis
Common height equals min of y2 minus max of y1 — same min-max logic on Y gives vertical overlap.

09:15 — Why Area Multiplication Fails With Negatives
Both negative into positive fakes an area — see the counterexample that breaks naive area greater than zero check.

10:30 — Fix With Width And Height Greater Than Zero
Return width greater than zero and height greater than zero — no multiplication, handles edge-touching correctly.

11:20 — Three Line Code Submit And Pass All Tests
Type three lines in Java, run samples, submit to pass all tests and grab Python C++ C from GitHub link above.

FAQ

Q1: How is a rectangle given in Rectangle Overlap LeetCode 836?
A1: As four integers x1 y1 x2 y2 where x1 y1 is bottom-left and x2 y2 is top-right. Two arrays rec1 and rec2 define the two rectangles to test.

Q2: When do two rectangles actually overlap?
A2: Only when both common width and common height are strictly greater than zero. Width is min of x2 minus max of x1, height is min of y2 minus max of y1. Edge touching returns false.

Q3: Why not just check if area greater than zero?
A3: When rectangles are on opposite sides both width and height are negative and their product becomes positive, faking a valid area. Checking width and height separately avoids that trap.

Q4: What is the time and space complexity?
A4: O(1) time and O(1) space — two mins, two maxes, two subtractions and two comparisons with no loops or extra structures.

Q5: Which companies ask Rectangle Overlap in interviews?
A5: Amazon, Adobe, Meta Facebook and Docusign. It looks easy but tests whether you handle projection overlap and edge cases correctly.

Q6: Does touching at an edge count as overlap?
A6: No. The overlapping area must be greater than zero, so sharing only a boundary line or a single point is not overlap and must return false.

Q7: Where can I get the code in all four languages?
A7: Java, Python, C++ and C are pushed to GitHub at the Solution link above. Use it to compare syntax and submit in your preferred language.

LeetCode #LeetCode836 #RectangleOverlap #CodingInterview #DSA #Algorithms #AmazonInterview #ShaanLabs


📺 Watch the full walkthrough on YouTube:

Watch the full Rectangle Overlap | LEETCODE 836 | Solve In Seconds | Amazon Most Asked Interview | walkthrough on YouTube


🔔 Love FAANG-style LeetCode walkthroughs? Don't solve alone — join 2,000+ coders getting daily breakdowns (Telegram is fastest):