The Full Counting Sort

  • + 1 comment

    OK, I give up. I don't understand what's wrong with my JavaScript code and testcase #5. I have tested locally and my output is exactly the same! but online is the only one it fails.

    Could anyone please give me a piece of advice?

    Here is my solution for this problem:

    function processData(input) {
        input = input.trim().split('\n');
        var n = parseInt(input[0]);
        var numbers = [];
        for (var i = 0; i < 100; i++) {
            numbers[i] = [];
        }
        var half = n / 2;
        for (i = 1; i <= n; i += 1) {
            var obj = input[i].trim().split(' ');
            var number = parseInt(obj[0]);
            var string = obj[1];
            if (i <= half) {
                string = '-';
            }
            numbers[number].push(string);
        }
        var result = '';
        for (i = 0; i < 100; i += 1) {
            var len = numbers[i].length;
            for (var j = 0; j < len; j += 1) {
                result += numbers[i][j] + ' ';
            }
        }
        console.log(result.trim());
    }
    

    I will also say that I've submitted it four times by now, and the reason is that I've been having a lot of troubles lately with some algorithms, my solution is fine and for no reason it aborts or stops, then when I resubmit my solution without any changes then it passes all testcases. It happened with the counting-sort3:

    https://www.hackerrank.com/challenges/countingsort3/submissions/code/24286586
    
    https://www.hackerrank.com/challenges/countingsort3/submissions/code/24285109
    

    and quicksort-in-place:

    https://www.hackerrank.com/challenges/quicksort3/submissions/code/24275323
    
    https://www.hackerrank.com/challenges/quicksort3/submissions/code/24275135
    

    please, help! :(