Skip to content

Latest commit

 

History

History
47 lines (33 loc) · 1.03 KB

_849. Maximize Distance to Closest Person.md

File metadata and controls

47 lines (33 loc) · 1.03 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : June 29, 2024

Last updated : June 29, 2024


Related Topics : Array

Acceptance Rate : 48.56 %


Solutions

Python

class Solution:
    def maxDistToClosest(self, seats: List[int]) -> int:
        maxx = 0
        indx = 0

        while not seats[indx] :
            indx += 1
        lastPerson = indx
        maxx = lastPerson
        
        for i, seat in enumerate(seats) :
            if seat :
                if maxx < (i - lastPerson) // 2 :
                    maxx = (i - lastPerson) // 2
                lastPerson = i
        
        maxx = max(maxx, len(seats) - lastPerson - 1)

        return maxx