I am getting wrong answer at test case no. 14. Also can anyone please explain the difference between the test case no 13 and 14 as they seem same to me.Please help.

There are a few bugs , some cases you missed

Bug 1 :

When you did this :

if(ans == 1)
{
for(int i=0;i<n;i++)
{
if(a[i]%3 == ans)
{
pos = i;
break;
}
}
// cout << ans << " " << a[pos] << endl;
for(int i=n-1;i>=0;i–)
{
if(pos!=i)
cout << a[i] ;
}
}

You’ve done for the case if there were some digits such that digit %3 == 1

But what happens if there isn’t.

Try to think how to solve then ( Hint : You managed to do that for ans==2 )

This bug fails the code for tests like :

5
3 2 2 0 0

actual output : 300

Bug 2 :

Even if you find a digit such that digit%3==1 , you should check are all the remaining digits 0 or not. This will prevent you from printing leading zeroes.

Your code fails this case :

3
0 0 1

actual : 0

This may be the case for test case 14 where your code failed

Bug 3 :

Again when you did this :

for(int i=n-1;i>=0;i–)
{
if(i!=pos1 and i!=pos2)
cout << a[i];
}

You should take care about if all the other digits are 0 or not.

Your code fails this test :

4
0 0 1 1

actual : 0

This may be the case for test case 14 where your code failed

Bug 4 :

Again here :

for(int i=n-1;i>=0;i–)
{
if(i!=ps)
cout << a[i];
}

You should check whether the other digits are all zero or not.

Your code fails this test :

3
0 0 2

actual : 0

This may be the case for test case 14 where your code failed

I hope there are no more bugs .Hope this helps . Don’t be disheartened by all these bugs. You’ll obviously do better and learn from your mistakes Good luck

3 Likes

Thanks for pointing out my mistakes.

1 Like

Finally solved it.

1 Like

Great Job !! =D Carry on

1 Like
//