Input: A[] = {1, 0, 1, 1, 0, 1}
Output: 2
?Explanation: One of the valid partitions of A = {1, 0, 1, 1, 0, 1} is {1, 0} and {1, 1, 0, 1} which satisfy above conditions.Hence we can partition an array into 2 subarrays.
Input: A[] = {1, 0, 0, 1, 0, 0, 1, 1}
Output: 1
Explanation: Here A = {1, 0, 0, 1, 0, 0, 1, 1} is itself not a palindrome. Then, no more partitioning needs to be done: just take A itself. Hence number of partitions of an array is 1.
Below is the implementation of the above approach.