Grumpy Bookstore Owner
MediumSliding Window
Decode it first. Clues, constraints, pattern and plan before any code.A shop is open for n minutes. customers[i] people visit during minute i. grumpy[i] is 1 if the owner is grumpy that minute (those customers leave unhappy) and 0 if not (they leave happy). The owner knows a trick to stay calm for minutes consecutive minutes, usable only once. Return the maximum number of happy customers over the whole day.
customers = [1, 0, 1, 2, 1, 1, 7, 5]
grumpy = [0, 1, 0, 1, 0, 1, 0, 1], minutes = 3 → 16Using the trick on the last three minutes saves 1 + 5 = 6 extra customers on top of the 10 who are already happy.
Constraints
1 <= minutes <= customers.length == grumpy.length <= 2 * 10^40 <= customers[i] <= 1000grumpy[i]is either0or1.