849. Maximize Distance to Closest Person

 avatar
unknown
python
3 years ago
404 B
2
Indexable
from math import *
class Solution:
    def maxDistToClosest(self, seats: List[int]) -> int:
        ans, zero = -1, seats.index(1)  #for leading 0's they are counted twice
        for i in seats:
            if i:
                ans = max(ans, ceil(zero/2))
                zero = 0
            else:
                zero += 1
        return max(ans, zero) #in case trailing 0's present