Code -> https://ide.codingblocks.com/s/34864
Question ->https://hack.codingblocks.com/contests/c/509/423
working fine in my ide and cb online ide but showing wrong output while submitting for one case !!.
Sorting in Linear Time
1 Like
In your code
line 4,5,6 are :
int n;
int a[n];
cin>>n;
Instead they should be :
int n;
cin>>n;
int a[n];
Actually you were creating array even before n was entered by the user, hence any random n was taken
Also in your code, line 9 is
if(a[i] > 2 && a[i] < 0){return 0;}
This is completely illogical, as a number can’t be both greater than 2 and less than 0 at the same time.
And this was not even needed, as when the question says that numbers will be only 1,2and 0, then you don’t need to check it
Thanks, bhaiya, actually I was coding from last night 4 hours and so while solving the assignment problems . . . my mind went crazy and I made those silly mistakes.