Tap here to switch tabs
Problem
Submissions

Problem: Maximize Distance to Closest Person

Maximize Distance to Closest Person asks you to choose an empty seat in a binary array so the nearest occupied seat is as far away as possible, then return that distance.

Statement

Given a binary array seats representing a row of seats, where seats[i] = 1 means the ithi^{th} seat is occupied and seats[i] = 0 means the ithi^{th} seat is empty, choose an empty seat for Alex such that the distance to the nearest occupied seat is maximized.

Return the maximum possible distance between Alex and the closest occupied seat.

Constraints:

  • 2≤2 \leq seats.length ≤2×104\leq 2 \times 10^4

  • seats[i] is either 00 or 11

  • At least one seat is empty

  • At least one seat is occupied

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximize Distance to Closest Person

Maximize Distance to Closest Person asks you to choose an empty seat in a binary array so the nearest occupied seat is as far away as possible, then return that distance.

Statement

Given a binary array seats representing a row of seats, where seats[i] = 1 means the ithi^{th} seat is occupied and seats[i] = 0 means the ithi^{th} seat is empty, choose an empty seat for Alex such that the distance to the nearest occupied seat is maximized.

Return the maximum possible distance between Alex and the closest occupied seat.

Constraints:

  • 2≤2 \leq seats.length ≤2×104\leq 2 \times 10^4

  • seats[i] is either 00 or 11

  • At least one seat is empty

  • At least one seat is occupied