Punch card streaks
EasyOnline Assessment
Count the free coffees a customer earned on a streak-based loyalty card.
The cafe records one number per calendar day for a customer: spend[i] is how much they spent that day, or -1 if the cafe was closed. On an open day, the customer extends their streak if they spent at least minimum; an open day with less spent (including 0) resets the streak to zero. A closed day (-1) is skipped entirely: it neither extends nor resets the streak.
Whenever the streak reaches goal_days days, the customer earns one free coffee and the streak starts again from zero. The days that earned a coffee are not counted towards the next one.
Input: spend, a list of integers in calendar order, goal_days, a positive integer, and minimum, a non-negative integer.
Output: the number of free coffees earned, as an integer.
Example 1
- Input:
- [[5,6,7,8,9,10],3,5]
- Output:
- 2
- Explanation
- Six open days all meet the minimum of 5. Days 1 to 3 earn a coffee and the streak restarts; days 4 to 6 earn a second one: 2.
Example 2
- Input:
- [[5,-1,6,2,9,-1,-1,9,9],3,5]
- Output:
- 1
- Explanation
- The streak builds 5, 6 (closed day skipped) and is wiped by the 2. Then 9 starts a new one, the two closed days change nothing, and 9, 9 complete the streak of three: 1 coffee.
Example 3
- Input:
- [[10,9,10,-1,12],1,10]
- Output:
- 3
- Explanation
- With a goal of 1 day, every open day that spends at least 10 earns a coffee: 10 and 10 and 12, while 9 earns nothing and the closed day is ignored: 3.
Constraints
0 <= spend.length <= 5,000spend[i] = -1(shop closed) or0 <= spend[i] <= 10,0001 <= goal_days <= 1000 <= minimum <= 10,000