My issue
I’m not able to solve this problem within the time limit. Please help!
My code
#include <stdio.h>
int countSubarrays(int arr[], int N, int K) {
int oddCount = 0;
for (int i = 0; i <= N - K; i++) {
int bitwiseOR = 0;
for (int j = i; j < i + K; j++) {
bitwiseOR |= arr[j];
}
if (bitwiseOR % 2 != 0) {
oddCount++;
}
}
return oddCount;
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
int N, K;
scanf("%d %d", &N, &K);
int A[N];
for (int i = 0; i < N; i++) {
scanf("%d", &A[i]);
}
int result = countSubarrays(A, N, K);
printf("%d\n", result);
}
return 0;
}
Problem Link: FIZZBUZZ2304 Problem - CodeChef