cin >> n;
set<int> st;
// since 100 is less than 2^8;
// we can store first 8 bits of all the strings
// and then run a loop from 0 to 101, the first number which is not present will be our answer, then we will fill rest of the bits with 0(or 1, doesn't matter).
for(int i=0; i<n; i++) {
cin >> str;
int ans = 0;
for(int i=0; i<min(n,8); i++) {
if(str[i]-'0') ans += (1<<i);
}
st.I(ans);
}
int element = 0;
while(st.find(element)!=st.end()) {
element++;
}
for(int i=0; i<min(n,8); i++) {
if((element>>i)&1) cout << 1;
else cout << 0;
}
for(int i=8; i<n; i++) {
cout << 0;
}
cout << endl;
Hey @iceknight1093 , I Know this may be a silly question, but how you mange to debug solutions so fast, I mean Yeah obviously you are a 6* Coder and have a lot of experience but is there some tips for us to debug solutions ao fast as you used to do.
Ps: Consider me as a beginner and also very new to community. <3
In this specific case I’ve solved these problems myself and seen discussions between the tester and setter about what could possibly be tricky cases/common wrong solutions, so if I see one of those I’ll know quickly
For C++ specifically, compiling with debug flags really helps (see this blog). Several solutions I’ve debugged had their issues revealed immediately when I just compiled them locally without even having to run the program (for example, I get a warning if a variable is used without its value being set)
Test on more than just the sample cases. The samples are often there just to make sure you haven’t completely misunderstood the problem, they don’t necessarily have to take all edge cases into account. If you aren’t sure where your program is going wrong, try lots of small cases. My comment immediately above shows that testing on even the most trivial case (n = 1) can bring out errors in your code.
Finally, you can always stress-test your solution. Either write a bruteforce or (if you have access to it) take a correct code from an accepted submission, then take your wrong code, generate lots of test cases, and compare the output. This will give you a testcase where you are failing, and you can then use that to debug your program.
Once you know a testcase where you’re wrong, general debugging advice still holds. Use lots of print statements and asserts to verify that your variables are actually holding the values you think they are, etc.
i have just changed the diagonal elements so the output string must be different from the given strings …please let me know where my code or the logic went wrong .
i have written my code in java.
Reader s=new Reader();
int t=s.nextInt();
while(t–>0) {
int n=s.nextInt();
String a[]=new String[n];
for(int i=0;i<n;i++) {
a[i]=s.readLine();
}
String ans="";
for(int i=0;i<n;i++) {
if(a[i].charAt(i)==‘0’)
ans+=“1”;
else
ans+=“0”;
}
System.out.println(ans);
I had to look at your actual submission to find the error. Please always link your code instead of pasting it here!
It seems like the reader class you’re using is an issue. I simply switched to taking input with Scanner and it passed (submission).
Unfortunately I know basically nothing about Java so I don’t really know why your Reader was wrong, you’ll have to figure that out yourself (or find someone who does know).