freedom.9
Senior Member
Python:
class Solution:
def maxSatisfied(self, customers: List[int], grumpy: List[int], minutes: int) -> int:
sumInRange, sumWithGrumpy, totalSum = 0, 0, 0
left, maxSofar = 0, 0
n = len(customers)
for right in range(n):
sumInRange += customers[right]
target = 0 if grumpy[right] == 1 else customers[right]
sumWithGrumpy += target
totalSum += target
maxSofar = max(maxSofar, sumInRange - sumWithGrumpy)
if right - left + 1 == minutes:
sumInRange -= customers[left]
sumWithGrumpy -= 0 if grumpy[left] == 1 else customers[left]
left += 1
return totalSum + maxSofar