Professional Documents
Culture Documents
Mock With Trang
Mock With Trang
Mock With Trang
Every minute, some number of customers (customers[i]) enter the store, and all those
customers leave after the end of that minute.
On some minutes, the bookstore owner is grumpy. If the bookstore owner is grumpy on
the i-th minute, grumpy[i] = 1, otherwise grumpy[i] = 0. When the bookstore owner is
grumpy, the customers of that minute are not satisfied, otherwise they are satisfied.
The bookstore owner knows a secret technique to keep themselves not grumpy for X
minutes straight, but can only use it once.
Return the maximum number of customers that can be satisfied throughout the day.
Input: [1,2,3,0,2]
Output: 4
1 3 0 2
4
[]
0
[7, 2, 3, 5, 0]
3
maximum profit
List of stock prices
-
[1,2,3,0,2]
int profit = 0;
int start = 0;
for(int i = 0; i < array.length-1; i++) {
if(array[i] > array[i+1]) {
profit += array[i] - array[start];
start = i + 1;
}
}
profit += array[array.length - 1] - array[start];
return profit;
}