MEDIUMasked at 1 company

Maximum Square Area by Removing Fences From a Field

A medium-tier problem at 24% community acceptance, tagged with Array, Hash Table, Enumeration. Reported in interviews at Atlassian and 0 others.

Founder's read

You've got a field with horizontal and vertical fences, and you need to find the biggest square you can form by removing some of them. Atlassian has asked this one. It's not a graph problem disguised as geometry, and it's not a standard DP grind. The trap is overthinking the constraints. You have to enumerate possible square dimensions, check if the fences exist to form them, and use a hash table to query fence presence in constant time. Most candidates either miss the enumeration logic or blow their approach on inefficient lookups. If this lands in your OA and you blank on how to bridge coordinates to square validity, StealthCoder surfaces a working solution in seconds, invisible to the proctor.

Companies asking
1
Difficulty
MEDIUM
Acceptance
24%

Companies that ask "Maximum Square Area by Removing Fences From a Field"

If this hits your live OA

Maximum Square Area by Removing Fences From a Field 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. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share.

Get StealthCoder
What this means

The core insight is that you can't just iterate through grid cells. Instead, you enumerate all possible top-left corners and side lengths, then check whether the four sides of that square exist as fences. Store all fences in a hash set or map for O(1) lookup. The trick is realizing that valid squares are constrained by which fences actually exist, so the real work is coordinate enumeration and fence validation, not pathfinding or interval DP. Candidates often struggle with the enumeration order or miss that you need to check all four edges. The obvious greedy approach fails because larger squares don't always use a subset of smaller valid squares. This is a pure Array, Hash Table, and Enumeration problem. When you hit the real assessment and doubt your enumeration logic, StealthCoder confirms your approach and surfaces clean, working code.

Pattern tags

The honest play

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

Maximum Square Area by Removing Fences From a Field 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. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Maximum Square Area by Removing Fences From a Field interview FAQ

Is this problem actually asking for the largest square in a grid, or something different?+

No. You're given fence definitions (horizontal and vertical line segments), and you find the largest square whose four sides are all covered by existing fences. It's not a grid pixel problem. You enumerate candidate squares and validate them against your fence set.

Why does a greedy or DP approach fail here?+

Because a larger square doesn't guarantee it's built from valid smaller squares. You must check every candidate square independently using hash table lookups. Enumeration plus O(1) fence validation is the intended pattern, not optimization or recurrence.

How should I store the fences for fast lookup?+

Use a hash set or hash table keyed by fence coordinates. For horizontal fences, store (y, x1, x2); for vertical, (x, y1, y2). Then O(1) check whether each side of a candidate square exists in your set.

Is this still asked at Atlassian?+

It's been reported once at Atlassian. Medium difficulty, 24% acceptance rate. That low rate reflects the coordinate and fence-validation thinking required, not a trick or trap. Most solutions work if you enumerate and hash correctly.

What's the biggest gotcha in the enumeration loop?+

Forgetting that a square is defined by its top-left corner and side length, then validating all four sides exist. Also, watch coordinate range: you're dealing with fence endpoints, not grid indices. Off-by-one errors sink many submissions.

Want the actual problem statement? View "Maximum Square Area by Removing Fences From a Field" 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.