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.
After several tests and 11 submissions, some of them failed and some other passed. This was my first original code with the Kakason's upgrades that passes all test cases.
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].split(' ');
numbers[parseInt(obj[0])].push(i <= half ? '-' : obj[1]);
}
for (i = 0; i < numbers.length; i += 1) {
for (var j = 0; j < numbers[i].length; j += 1) {
process.stdout.write(numbers[i][j] + ' ');
}
}
}
In conclusion, YES, concatenating the resulting string is too big for this environment that it doesn't fit, and in those cases is better to use process.stdout.write to print in-line instead of console.log because this adds breaking lines.
I really hope this can help others JS developers, and please thank Kakason, I couldn't do it without him.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
The Full Counting Sort
You are viewing a single comment's thread. Return to all comments →
After several tests and 11 submissions, some of them failed and some other passed. This was my first original code with the Kakason's upgrades that passes all test cases.
In conclusion, YES, concatenating the resulting string is too big for this environment that it doesn't fit, and in those cases is better to use process.stdout.write to print in-line instead of console.log because this adds breaking lines.
I really hope this can help others JS developers, and please thank Kakason, I couldn't do it without him.