Can someone help me debug the code of 'Beautiful Array' (BTAR)?

I am getting WA.
I tried many custom cases but not able to find the case giving wrong answer.
Please help me!
Here is my code:

My solution

1 Like

if(a[1]!=0)
{
c+=2*(a[1]/4);
a[1]%=4;
}
if(a[3]!=0)
{
c+=2*(a[3]/4);
a[3]%=4;
}

in this part of your code you should do c+=3 *(a[1]/4) and 3 *(a[3]/4) instead as it would take 3 steps to combine 4 1s and 4 3s

1 Like

Hey @assassin28,

Try this TC:

6  
1 1 2 1 1 2

Expected output: 4 [{(1+1)+2}+{(1+1)+2}].
Your code gives: no output
Check it here: https://code.hackerearth.com/88cca6k?key=62e360ba986a5e7ae749f9f4a7a1fbc4
Consider modifying last elif or/and add another conditional expression.
Hope this helps!

2 Likes

Thank you!
That was the exact problem.

Yes,there was a problem in last elif as told by @mohitkurani98.
And your test case helped too.

1 Like

WOW! That’s great!! I wrote the answer for @assassin28 but for some reason he deleted his question.