Minimum Rest Days
Alex has N days of free time. The activity options available on each day are represented by an array A of length N, where A[i] indicates the options for the i-th day:
- 0: No options available.
- 1: Can write code.
- 2: Can work out.
- 3: Can either write code or work out.
Alex can choose to write code, work out, or rest on any given day. However, Alex cannot do the same active task (writing code or working out) on two consecutive days. Resting is always an option and has no consecutive restrictions.
Find the minimum number of rest days Alex will take if they schedule their activities optimally.
Example 1:
Input: N = 4 , arr = [1, 3, 2, 0]
Output: 2
Explanation Best schedule:
Day 1 → code Day 2 → workout Day 3 → code Day 4 → rest
Rest days = 2
Example 2:
Input: N = 7 , arr = [1,3,3,2,1,2,3]
Output: 0
Explanation : Alternate activities → no rest needed.
Day 1 → code Day 2 → workout Day 3 → code Day 4 → workout Day 5 → code Day 6 → workout Day 7 → code
Now Your Turn!
Pick the correct output for the given inputInput : N = 7 , arr = [1,0,0,3,1,2,2]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= N <= 105
- a[i] ∈ {0,1,2,3}