[
array
groupby
]
BinarySearch 0195 Seat Arrangement
Problem statement
https://binarysearch.com/problems/Seat-Arrangement/
Solution
Equal to Leetcode 0605. Can Place Flowers.
Complexity
It is O(n)
for time and space.
Code
class Solution:
def solve(self, n, seats):
t = [len(list(j)) for i, j in groupby([0] + seats + [0])]
return sum((i-1)//2 for i in t[0::2]) >= n