The task is to find how many arrays are there which can be transformed to array Y[] such that the last element is 1.
Input: arr[] = {'& ', '|'}
Output: 5
Explanation: N = 2, we have eight possible binary arrays of size N + 1, ( {0, 0, 0}, {0, 0, 1}, {0, 1, 0}, {1, 0, 0}, {0, 1, 1}, {1, 0, 1}, {1, 1, 0} and {1, 1, 1} )
we will transform each of them into Y by the above rules and check whether they end with 1 or 0. If they end with 1 that means they will be counted in our answer.
array 1: X = {0, 0, 0}
Y[0] = X[0] = 0
Y[1] = Y[0] & X[1] = 0 & 0 = 0
Y[2] = Y[1] | X[2] = 0 | 0 = 0
Finally, Y for X is {0, 0, 0} as it does not end with 1 it will not be counted in our answer.
array 2: X = {0, 0, 1}
Y[0] = X[0] = 0
Y[1] = Y[0] & X[1] = 0 & 0 = 0
Y[2] = Y[1] | X[2] = 0 | 1 = 1
Finally, Y for X is {0, 0, 1} as it ends with 1 it will be counted in our answer.
array 3: X = {0, 1, 0}
Y[0] = X[0] = 0
Y[1] = Y[0] & X[1] = 0 & 1 = 0
Y[2] = Y[1] | X[2] = 0 | 0 = 0
Finally, Y for X is {0, 0, 0} as it does not end with 1 it will not be counted in our answer.
array 4: X = {1, 0, 0}
Y[0] = X[0] = 1
Y[1] = Y[0] & X[1] = 1 & 0 = 0
Y[2] = Y[1] | X[2] = 0 | 0 = 0
Finally Y for X is {1, 0, 0} as it does not end with 1 it will not be counted in our answer.
array 5: X = {0, 1, 1}
Y[0] = X[0] = 0
Y[1] = Y[0] & X[1] = 0 & 1 = 0
Y[2] = Y[1] | X[2] = 0 | 1 = 1
Finally Y for X is {0, 0, 1} as it end with 1 it will be counted in our answer.
array 6: X = {1, 0, 1}
Y[0] = X[0] = 1
Y[1] = Y[0] & X[1] = 1 & 0 = 0
Y[2] = Y[1] | X[2] = 0 | 1 = 1
Finally Y for X is {1, 0, 1} as it end with 1 it will be counted in our answer.
array 7: X = {1, 1, 0}
Y[0] = X[0] = 1
Y[1] = Y[0] & X[1] = 1 & 1 = 1
Y[2] = Y[1] | X[2] = 1 | 0 = 1
Finally Y for X is {1, 1, 1} as it end with 1 it will be counted in our answer.
array 8: X = {1, 1, 1}
Y[0] = X[0] = 1
Y[1] = Y[0] & X[1] = 1 & 1 = 1
Y[2] = Y[1] | X[2] = 1 | 1 = 1
Finally Y for X is {1, 1, 1} as it end with 1 it will be counted in our answer.
Total count of binary arrays that end with 1 are 5
Input: arr[] = {'|', '|', '|', '|', '|'}, K = 0
Output: 63