The Full Counting Sort

  • + 2 comments

    My solution works fine on TestCase0 but it fails all the other tests. I downloaded TestCase1 input and output and on review found that the output is incorrect. The first few elements of output are- '- - - - - - - - - pq qy uz eb fo'. However, 'eb' is 104th element in the input and in the first half of a 1000 element array and therefore, should be replaced by a '-'. There are other smiliar discrepencies as well. Am I missing something?

    • Asked to answer
      + 1 comment

      If what you say is true then I would agree but seeing how so many people successfuly implemented a solution, I'd say there is something wrong here. I cannot look at the test case 1, can you link to it? More importantly, can you link your code?

      • + 1 comment

        Thanks for replying, Victor. Here is the link to my submission-

        https://www.hackerrank.com/challenges/countingsort4/submissions/code/20064820

        And here are the links to test case 1-

        input-

        https://hr-testcases-us-east-1.s3.amazonaws.com/444/input01.txt?AWSAccessKeyId=AKIAJAMR4KJHHUS76CYQ&Expires=1462121468&Signature=NK9sOzQ2T2x8SHTTzryUEqyuKaE%3D&response-content-type=text%2Fplain

        output-

        https://hr-testcases-us-east-1.s3.amazonaws.com/444/output01.txt?AWSAccessKeyId=AKIAJAMR4KJHHUS76CYQ&Expires=1462121473&Signature=jRG1aKMJGayuliBU31TH5LRDMQo%3D&response-content-type=text%2Fplain

        I am not sure if the links above are public. If they do not work, then I can upload the files (if possible). Please let me know if you have other questions or concerns. Thanks.

        • + 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)

    • Asked to answer
      + 0 comments

      Also, are you sure it's not failing because of a timeout?