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.
The outer loop is defined and not reliant on the input N, thus it does not grow with the input. It is O(100n), which is same as O(n).
I think a better solution would however be to not store the scanned ints, as we do not need them once we record their appearence.
1.Create array size 100
2. For 0 to n, array[scanner.nextInt()]++;
3. Seperate loop afterwards goes from 0 to 100 and prints out array[i] + " ". (for formatting purposes).
This makes it O(n) + O(100), which is simply O(n).
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Counting Sort 1
You are viewing a single comment's thread. Return to all comments →
The outer loop is defined and not reliant on the input N, thus it does not grow with the input. It is O(100n), which is same as O(n).
I think a better solution would however be to not store the scanned ints, as we do not need them once we record their appearence.
1.Create array size 100 2. For 0 to n, array[scanner.nextInt()]++; 3. Seperate loop afterwards goes from 0 to 100 and prints out array[i] + " ". (for formatting purposes).
This makes it O(n) + O(100), which is simply O(n).