Sorting in linear time

Why the testcases are failing ?

@vaishnavtannu,

  • Line 27: if(a[m==1]) should be -> if (a[m] == 1)

Also a logical error is present, try to think on this test case:

3
1 2 0

Solution accepted now. Also for the testcase 1 2 0 when I change if to else if in line 27 i am getting the correct output. Can you please explain why using only ‘if’ in line 27 is giving wrong answer.

@vaishnavtannu,
Because in

  • Line 24 : m++

so if the first if i.e if(a[m]==0) is satisfied, m++ will happen, and then the next if i.e if(a[m]==1) will be checked with the new updated value of m, whereas if you write else if in the second if, then at a time only one of them will be checked.