MEDIUMasked at 8 companies

Maximize Distance to Closest Person

A medium-tier problem at 49% community acceptance, tagged with Array. Reported in interviews at VK and 7 others.

Founder's read

You're given an array of seats, some occupied, some empty. Your job: place one person in an empty seat such that the distance to the nearest occupied seat is maximized. Sounds simple until you realize brute force tanks on large arrays. VK, Roblox, Samsung, Amazon, and Snap have all asked this. The acceptance rate sits at 49%, which means half the candidates in your assessment room will get stuck on the optimization step. If you blank on the greedy insight during your live OA, StealthCoder surfaces the working solution in seconds, invisible to the proctor.

Companies asking
8
Difficulty
MEDIUM
Acceptance
49%

Companies that ask "Maximize Distance to Closest Person"

If this hits your live OA

Maximize Distance to Closest Person 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 because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround.

Get StealthCoder
What this means

The trap is simulating every empty seat and checking distances each time, which balloons to O(n^2) or worse. The real pattern: find the largest gap between two occupied seats, or between an edge and the nearest occupied seat, then place your person in the middle of that gap. You can solve this in a single pass by tracking gaps and calculating the maximum distance you can achieve. The trick is recognizing that you don't need to evaluate all seats individually, you only need to find the widest gap. Most candidates waste time on nested loops when they should be thinking about gaps as intervals. If this problem hits your assessment and you freeze on the optimization, StealthCoder runs invisibly during screen share and gives you the linear-time approach.

Pattern tags

The honest play

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

Maximize Distance to Closest Person 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 because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Maximize Distance to Closest Person interview FAQ

Is this really a medium problem?+

The 49% acceptance rate confirms it. The Array foundation is straightforward, but the greedy insight about maximizing gap midpoints trips up half the field. It's medium because the trick isn't obvious on first read, not because the code is complex.

Do I need to know a special algorithm?+

No. You need to think about the problem geometrically: find the largest gap, place the person in its center, compute the distance. One pass through the array, track gaps, return the max. It's a pattern recognition problem, not a data-structure problem.

Will Amazon ask this the same way?+

Amazon is in the list of companies that have asked it. They may tweak constraints or ask you to return the index instead of the distance, but the core insight stays the same. If you understand gaps and midpoints, you're covered.

What if all seats are empty or all occupied?+

Edge case, yes. If all are empty, the answer is typically half the array length (place at the end). If all are occupied, the answer is 0. Your solution must handle these without crashing. Test them first.

How does this relate to real interview prep?+

This is a filtering problem that teaches you to spot gaps and intervals in arrays. That pattern shows up in meeting rooms, capacity constraints, and load balancing questions. It's a stepping stone, not just a standalone drill.

Want the actual problem statement? View "Maximize Distance to Closest Person" 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.