The Full Counting Sort

  • + 0 comments

    Indeed, as expected, the test cases are not public. It's alright, I got them myself because I was curious.

    Your code works fine the problem is that it is not implementing the right algorithm. Upon re-reading the problem statement, I noticed that you should treat the input as if it were written this way:

    6

    0 - (was "is")

    3 - (was "eb")

    3 - (was "whatever")

    2 right

    0 this

    1 is

    Will output "- this is right - - " while your code outputs "- this - right - - "

    As you can see, the "is" in the first half of the array is replaced by a dash. The second one, however, is kept.

    Now you need to get rid of "firstHalfMap" and find another way to do it :) Good luck!

    General advice:

    • Instead of a Map, use a Set, it is pretty much the same thing but more memory efficient and made just for that.

    • Java int arrays are initialized to all 0 by default, so no need to do it yourself. If you want to initialize with another number, use "Arrays.fill"

    • You are using a lot of different arrays here and there which makes things confusing. If you can, use as few data structures and variables as possible. (You can take a look at my code to see what I mean: https://www.hackerrank.com/challenges/countingsort4/submissions/code/20078506)