We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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:
The Full Counting Sort
You are viewing a single comment's thread. Return to all comments →
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:
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:
and quicksort-in-place:
please, help! :(