1052. Grumpy Bookstore Owner
First completed : June 20, 2024
Last updated : June 20, 2024
Related Topics : Array, Sliding Window
Acceptance Rate : 57.099 %
To see the question prompt, click the title.
class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], minutes: int) -> int:
currentlySatisfied = sum(customers[x] for x in range(len(customers)) if not grumpy[x])
satisfied = [0] * len(grumpy)
maxx = 0
for i in range(len(grumpy)) :
if grumpy[i] :
currentlySatisfied += customers[i]
if i - minutes >= 0 and grumpy[i - minutes] :
currentlySatisfied -= customers[i - minutes]
if currentlySatisfied > maxx :
maxx = currentlySatisfied
satisfied[i] = currentlySatisfied
return maxx