Input: arr[] = { 1, 1, 1, 0, 1, 0, 0, 0 }
Output: 2
Explanation:
Reversing the subarray {arr[1], ..., arr[5]} modifies arr[] to { 1, 0, 1, 0, 1, 1, 0, 0 }
Reversing the subarray {arr[5], arr[6]} modifies arr[] to { 1, 0, 1, 0, 1, 0, 1, 0 }, which is alternating. Therefore, the required output is 2.
Input: arr[] = { 0, 1, 1, 0 }
Output: 1
Explanation:
Reversing the subarray {arr[2], ..., arr[2]} modifies arr[] to { 0, 1, 0, 1 }, which is alternating. Therefore, the required output is 1.