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.
Wow! Kakason, thank you very much for your time and debugging my code. It passed all the test cases! Bravo! But now, I have several questions and I hope this can help others with the same problem:
Before submitting the last working version (yours), I attempted another following the recomendations you gave me but it didn't pass test case #5, here is the code:
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);
}
for (i = 0; i < 100; i += 1) {
var len = numbers[i].length;
for (var j = 0; j < len; j += 1) {
process.stdout.write(numbers[i][j] + ' ');
}
}
}
As you can see, I didn't concatenate the answer and I used the process.stdout.write instead of console, and that would be the first question, why? is there some benefit using process.stout?
Second, if you agree, that code should work too, but as I said, it didn't, so? what would it be the real problem? There are several diferences between your code and mine, 1. you're not using the trim() function, and I've gotten used to use it because there where some troubles with whitespaces in some exercises. 2. the ++ operator. 3. the name of my variable 'string' and 4.pre calculating the numbers[i].length. Which of all of these differences is causing the real problem? I'm going to test all of them and see what are the results.
Thanks again Kakason.
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 →
Wow! Kakason, thank you very much for your time and debugging my code. It passed all the test cases! Bravo! But now, I have several questions and I hope this can help others with the same problem: Before submitting the last working version (yours), I attempted another following the recomendations you gave me but it didn't pass test case #5, here is the code:
As you can see, I didn't concatenate the answer and I used the process.stdout.write instead of console, and that would be the first question, why? is there some benefit using process.stout?
Second, if you agree, that code should work too, but as I said, it didn't, so? what would it be the real problem? There are several diferences between your code and mine, 1. you're not using the trim() function, and I've gotten used to use it because there where some troubles with whitespaces in some exercises. 2. the ++ operator. 3. the name of my variable 'string' and 4.pre calculating the numbers[i].length. Which of all of these differences is causing the real problem? I'm going to test all of them and see what are the results.
Thanks again Kakason.