Skip to content

Instantly share code, notes, and snippets.

@deepaknverma
Created April 27, 2017 06:17
Show Gist options
  • Save deepaknverma/09cf426fc8b6afa2091540ca677fcfe9 to your computer and use it in GitHub Desktop.
Save deepaknverma/09cf426fc8b6afa2091540ca677fcfe9 to your computer and use it in GitHub Desktop.
Hacker Rank Solution: Counting Sort 1
This file has been truncated, but you can view the full file.
/*
Sample Output
0 2 0 2 0 0 1 0 1 2 1 0 1 1 0 0 2 0 1 0 1 2 1 1 1 3 0 2 0 0
2 0 3 3 1 0 0 0 0 2 2 1 1 1 2 0 2 0 1 0 1 0 0 1 0 0 2 1 0 1
1 1 0 1 0 1 0 2 1 3 2 0 0 2 1 2 1 0 2 2 1 2 1 2 1 1 2 2 0 3
2 1 1 0 1 1 1 0 2 2
Explanation
The output states that 0 appears 0 times, 1 appears 2 times,
2 appears 0 times, and so on in the given input array.
*/
function counter(input) {
let arr = (input.split('\n')[1]).split(' ').map(Number);
const newArr = [];
for(var i=0; i < 100; i++) {
newArr.push(arr.reduce((n, val) => { return n + (val === i); }, 0));
}
process.stdout.write(newArr.join(' '));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment