Skip to content

Latest commit

 

History

History
48 lines (31 loc) · 1.1 KB

_1052. Grumpy Bookstore Owner.md

File metadata and controls

48 lines (31 loc) · 1.1 KB

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.

Solutions

Python

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