Grumpy Bookstore Owner
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
A shop is open for n minutes. During minute i, customers[i] people arrive and leave at the end of that minute. The owner is grumpy during minute i when grumpy[i] == 1 and calm when grumpy[i] == 0. Customers who arrive during a calm minute are satisfied; customers who arrive during a grumpy minute are not.
The owner knows a trick that keeps them calm for exactly minutes consecutive minutes, and can use it at most once. Return the maximum total number of satisfied customers over the whole day.
Aim for O(n) time.
Examples
Constraints
- 1 <= n <= 2 * 10^4
- `customers.length == grumpy.length == n`
- 0 <= customers[i] <= 1000
- `grumpy[i]` is 0 or 1
- 1 <= minutes <= n
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.