My issue
include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin >> t;
while(t–) {
string num;
cin >> num;
int count_0=0, count_1=0;
for(int i = 0; i < num.length(); i++) {
if(num[i] == '0') count_0++;
else count_1++;
}
if(count_0==1 || count_1==1) cout << "YES\n";
else cout << "NO\n";
}
return 0;
}
//I am not getting the error is this problem. But it showing some hidden wrong test cases, Why?
My code
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin >> t;
while(t--) {
string num;
cin >> num;
int count_0=0, count_1=0;
for(int i = 0; i < num.length(); i++) {
if(num[i] == '0') count_0++;
else count_1++;
}
if(count_0==1 || count_1==1) cout << "YES\n";
else cout << "NO\n";
}
return 0;
}
Problem Link: Chef and digits of a number Practice Coding Problem