[
array
groupby
]
BinarySearch 0871 Maximize Social Distancing
Problem statement
https://binarysearch.com/problems/Maximize-Social-Distancing/
Solution
Equal to Leetcode 0849. Maximize Distance to Closest Person.
Complexity
It is O(n)
for time and space.
Code
class Solution:
def solve(self, seats):
out = max(seats[::-1].index(1), seats.index(1))
for seat, group in groupby(seats):
if seat: continue
out = max(out, (len(list(group))+1)//2)
return out