Chef ans Tetris

please help me to figure out what is wrong with my solution

1 Like

This happened with me as well.

It is happening because of n=1.

Just a separate if statement for n=1 needs to be added.

my wrong solution

my correct solution

your corrected solution


thank you @prakhariitd

Welcome :slight_smile:

Please tell me what’s wrong with this :

Thanks in advance.

Try this testcase

5 3 3 4 
10 2 6 7

your code outputs -1, but the answer is 10.

1 Like

Please tell me what’s wrong with this


The order of those if statements in your code is wrong, b[j-1] has to be given preference because it can’t be added to a[j+1].

Therefore if statements having b[j-1] should be placed above others, and a few permutations can be tried :wink:

I just changed the order of if statements, in your code and got AC.

your corrected solution

1 Like

Can you please tell the problem in this solution?


Again the order of if and else if statements is wrong.

your corrected solution

1 Like


can you again explain why the ordering is important here… i am not getting the logic behind this