MEDIUMasked at 1 company

Find the Largest Area of Square Inside Two Rectangles

A medium-tier problem at 45% community acceptance, tagged with Array, Math, Geometry. Reported in interviews at Cisco and 0 others.

Founder's read

You're given two rectangles and need to find the largest square that fits inside both of them at the same time. Cisco has asked this one. The obvious move, just take the minimum dimension and square it, fails because the rectangles might not overlap, or their overlap might be a thin strip that doesn't give you a square at all. You need to figure out the actual intersection geometry first, then find the max square that fits in that intersection. It's a geometry problem disguised as an optimization problem, and the gap between a brute-force guess and a correct solution is wide. If you hit this live and blank on the overlap logic, StealthCoder surfaces the working approach in seconds, invisible to the proctor.

Companies asking
1
Difficulty
MEDIUM
Acceptance
45%

Companies that ask "Find the Largest Area of Square Inside Two Rectangles"

If this hits your live OA

Find the Largest Area of Square Inside Two Rectangles is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made for the engineer who has done the work but might still blank with a webcam pointed at him.

Get StealthCoder
What this means

The trap is assuming the two rectangles always overlap meaningfully. Step one: compute the intersection rectangle. If there's no overlap, the answer is zero. If there is, you get a rectangle defined by (left, bottom, right, top) coordinates. The largest square that fits inside that intersection is constrained by the shorter of its two dimensions (width or height). But that's only true if the intersection itself is a valid rectangle. Common pitfall: candidates compute the intersection wrong, mixing up coordinate systems or forgetting to check that the resulting bounds are valid (left < right and bottom < top). Once you have the valid intersection, the answer is the minimum of width and height, squared. The math is simple once geometry is right. This is medium difficulty because most candidates skip or mess up the intersection logic and jump straight to the dimension squaring. StealthCoder handles the coordinate bookkeeping and validates the geometry so you don't lose points to a careless overlap bug.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Find the Largest Area of Square Inside Two Rectangles recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made for the engineer who has done the work but might still blank with a webcam pointed at him. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Find the Largest Area of Square Inside Two Rectangles interview FAQ

What if the two rectangles don't overlap?+

The intersection is empty, so there's no square that fits in both. Return 0. The tricky part is detecting this correctly: check whether left < right and bottom < top for your computed intersection. If either condition fails, there's no valid overlap.

How do I compute the intersection of two rectangles?+

For each rectangle, you have a left, right, bottom, and top. The intersection's left is the max of the two lefts, right is the min of the two rights, bottom is the max of the two bottoms, top is the min of the two tops. Then validate: if left >= right or bottom >= top, there's no overlap.

Is this still asked at Cisco or other big companies?+

Cisco is on record asking it. It's not as common as array or graph problems, but geometry and math problems still show up in OAs, especially for roles that touch graphics, spatial systems, or optimization.

What's the trick to solving this efficiently?+

There's no hidden trick. Once you have the intersection rectangle, the largest square that fits inside is simply the minimum of its width and height, squared. The real work is getting the intersection logic right. Most failures are coordinate mistakes, not algorithmic ones.

Does the input format matter, and how do I handle different coordinate systems?+

Input can vary: some problems give (x1, y1, x2, y2), others give (left, bottom, right, top). Read the problem carefully. Stay consistent with your naming throughout. Test your intersection logic on a simple example like two overlapping squares to catch coordinate bugs early.

Want the actual problem statement? View "Find the Largest Area of Square Inside Two Rectangles" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.