Grumpy Bookstore Owner LeetCode solution in Java

1
class Solution {
2
public int maxSatisfied(int[] customers, int[] grumpy, int minutes) {
3
int start = -1;
4
int count = 0;
5

6
int max = 0;
7
int curr = 0;
8

9
for (int i = 0; i < customers.length; i++) {
10
if (grumpy[i] == 0) {
11
count += customers[i];
12
} else {
13
curr += customers[i];
14
}
15

16
if (i - start > minutes) {
17
start++;
18
if (grumpy[start] == 1) {
19
curr -= customers[start];
20
}
21
}
22
max = Math.max(max, curr);
23
}
24

25
return count + max;
26
}
27
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0