You are given an array A of N integers. If you make the array whole using the following operation, then what is the minimum number of operations required to make the entire array even?
Note : It can be proved that this is always possible.
Operation
Select an index
and perform operation:
P=A[i]+A[i+1]; Q=A[i]-A[i+1];
A[i]=P; A[i+1]=Q;
link to whole question
this is my code
for i in range(int(input())):
N=int(input())
arr=list(map(int,input().split()))
dic=[i for i in range(N) if arr[i]%2!=0 ]
value=0
for i in range(len(dic)-1):
k=dic[i+1]-dic[i]
value+=k
print(value)
testcases.............
testcase1:
N=6
arr= 1 6 4 3 4 2
my output = 3
expected output = 4
i do not get how come four operations is need in this testcase were as it only need three operation .
testcase 2:
N=6
arr = 1 6 4 3 5 2
my output = 4
expected output =3
in this testcase all the integers will not be converted into even number no matter how many operations we applied .
if someone could show me how come testcase2 is done in three operation .
testcase1 will be done in four operation .
and were i am doing it wrong
can it be solved with bit manipulation.