2
public int maxDistToClosest(int[] seats) {3
int size = seats.length;8
for (int i = 0; i < size; i++) {10
start = end; // update start to end when we have a filled seat.11
end = i; // update end with i pointer when we have a filled seat.12
if (start == -1) max = i; // for special case when there is only '1' in the array13
else max = Math.max((end - start) / 2, max); // updating max.17
// Handeling speical cases before returning max.18
// 1) last element is 0 as we wont be updating max for that in above loop.19
// 2) when there only single '1' in the array, we need to make sure whether right half is bigger20
// than the left half.22
if (seats[size - 1] == 0 || start == -1) return Math.max(max, (size - 1 - end));