Can somebody tell me why is my solution wrong?

My code is running and showing correct output in my IDE but when i submit on Codechef, it shows wrong answer. Can somebody help me out to identify what is wrong in my code and how can it correct it?

Here is the link to my solution:

Line 30 : instead of 0, you have to initialise it by w[I].

I don’t think so this would be the problem because i didn’t increment “i” so it will automatically take the value a[i] in next step.
Though i tried running after making the specified changes, it didn’t even pass the sample test cases.

Here is your code with slight modification.
Cases that were not necessary, I have commented those.
and I have initialised count=1;

1 Like

Your code fails for this test case:
4 7
1 1 6 3

I think to correct your code you just need to sort the array in ascending order.

Your code fails this test case:
2 7
1 7
Expected: 2, Output: 1

I think this change will do the job:
{ wt=0; count++; }

1 Like

Yes it worked. Thanks for the help!

1 Like