My issue
what is fault in my code ?
My code
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int N, X;
cin >> N >> X;
long long int S;
cin >> S;
int arr[N];
// Fix the loop condition for filling the array
for (long long int i = 0; i < N; i++) {
arr[i] = S % 10;
S = S / 10;
}
long long int countofO = 0;
if (arr[N-1] == 0) {
cout << "NO" << endl;
continue;
} else {
for (long long int i = N - 1; i >= 0; i--) {
if (countofO > X) {
break;
}
if (arr[i] == 1) {
countofO = 0;
continue;
} else {
countofO++;
}
}
if (countofO > X) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
}
return 0;
}
Problem Link: Access Control Practice Coding Problem - CodeChef