I was trying to solve this problem on leetcode.
You are given a 0-indexed integer array nums. You have to partition the array into one or more contiguous subarrays.
We call a partition of the array valid if each of the obtained subarrays satisfies one of the following conditions: ...
- The subarray consists of exactly 2 equal elements. For example, the subarray [2,2] is good.
- The subarray consists of exactly 3 equal elements. For example, the subarray [4,4,4] is good.
- The subarray consists of exactly 3 consecutive increasing element, For example, the subarray [3,4,5] is good
The problem is that there are two examples:
- [4,4,4,5,6] - Valid (The array can be partitioned into the subarrays [4,4] and [4,5,6].)
- [1,1,1,2] - Invalid
I expected example two to be valid as well since [1,1] and [1,1,1] both satisfy conditions 1 and 2 respectively.
So, why is it invalid?