The Full Counting Sort

  • + 1 comment

    I submitted the change and it really works for me :)
    Here is the code:

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

    Since the size of testcase#5 is too large, I still can't figure out the reason why your string operation(result += numbers[i][j] + ' ') is wrong. But if u puts process.stdout.write outside the for loop i.e. use process.stdout.write to print result directly, it will be WA. Hence, it it the reason why I think the string operation has problem.