Counting sort (why testcase is giving wrong answer)

Hello @Saksham12,

Your Code will fail for the case when numbers are repeating:
Example:
3 2 4 1 3 5
Expected Result:
1 2 3 3 4 5
Your Output:
1 2 3 4 5

Solution:

  1. You have to print i, freq[i] times.
  2. Initialize your freq[] array with 0.

Modified Code:

Hope, this would help.
Give a like if you are satisfied.

1 Like

Thanks for the modification

Anytime @Saksham12,

Please, mark this doubt as resolved.

I am currently not doing the work I will mark it resolved later

okay @Saksham12,

You can also ask doubt if you have any, related to this question.