Task #2 gives WA

#include <bits/stdc++.h>
using namespace std;

int main() {
// your code goes here
int t;
cin >> t;
while(t–) {
int n;
cin >> n;
vector A(n);
for(auto &x: A)
cin >> x;
int jump = 0;
vector SP(n);
vector DP(n);
int parity = A[0] % 2;
if(A[0] % 2 == A[n - 1] % 2) {
for(int i = 1; i < n; i++) {
if(A[i] % 2 == parity)
jump++;
}
cout << jump << endl;
} else {
SP[0] = 0;
for(int i = 1; i < n; i++) {
SP[i] = SP[i - 1];
if(A[i] % 2 == parity) {
SP[i]++;
}
}
DP[n - 1] = 1;
for(int j = n - 2; j >= 0; j–) {
DP[j] = DP[j + 1];
if(A[j] % 2 == 1 - parity) {
DP[j]++;
}
}
int ans = INT_MAX;
for(int i = 0; i < n; i++) {
ans = min(ans, DP[i] + SP[i]);
}
cout << ans << endl;
}
}

return 0;

}

Check the following solution which has slightly different DP approach.

Accepted