Maximize Distance to Closest Person
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
A row of seats is described by the array seats, where 1 marks an occupied seat and 0 an empty one. At least one seat is empty and at least one is occupied.
Alex wants to sit in an empty seat that is as far as possible from the nearest occupied seat. The distance between seats i and j is |i - j|.
Return the largest possible distance from Alex to the closest person.
Examples
Constraints
- 2 <= seats.length <= 2 * 10^4
- `seats[i]` is 0 or 1.
- At least one seat is empty and at least one is occupied.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.