- Practice
- Algorithms
- Sorting
- Counting Sort 1
- Discussions

# Counting Sort 1

# Counting Sort 1

byscul + 6 comments Array we create for keeping numbers is 0 to 100 not 0 to N. Just keep that in mind ;)

ajay_kathpal + 0 comments i missed that in first submission :p

littleninja + 0 comments Great tip, also got me. Using N = 100 in the example was a bit misleading.

aayushis + 1 comment Hey, I dont understand the problem statement.Can you please elaborate

rajatsingh25aug + 0 comments create a map for

****long long ** **datatype,as the limit is 10^6. Then add the element accordingly. you dont even need an array for storing elements,just create a map and done :).

avi_cindrella + 0 comments i submitted like 10 times ..then i saw your comment :P ..thanks

dat_bui + 0 comments Thanks, hackerrank catched me)

ygaur697 + 0 comments Liteally every one gets stuck here!

ethanjustis + 0 comments Simple C implementation. Solved in real-time, and uses input from ar[] as index for arCount[]. Notice there is no need to permanently store ar[] values, only temporarily.

`for(i = 0; i < n; i++) { scanf("%d", &index); arCount[index)]++; } for(i = 0; i < 100; i++) printf("%d ", arCount[i]);`

Nicke + 0 comments As the despription says, there's no need to sort anything. Just create a new empty array 0-100 and loop through the list of the provided numbers. For each number, then do array[x]++ to count it. That's all there is to it. My solution in C#:

int[] range = new int[100]; int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); foreach (int x in nums) range[x]++; Console.WriteLine(String.Join(" ", range));

rafael_aguilar_1 + 1 comment The test#1 expects to print the numbers with 0 appearances but the other test cases doesn't. I think this is a very missleading test.

This is how I workaround it with Python3:

k = int(input()) results = [0]*k for i in input().split(' '): results[int(i)] += 1 if k != 100: print(' '.join([repr(num) for num in results if num])) else: print(' '.join([repr(num) for num in results]))

Ardillo + 0 comments Last part is redundant, this works better:

__ = input() sol = [0] * 100 for i in [int(n) for n in input().split()]: sol[i] += 1 print(*sol)

Sharma_123 + 1 comment can anyone explain me the sample output?

larachicharo + 1 comment You dont have to print a list representing the original array. Print it in order. How many times does 2, 3, 4, ..., is in the array? is what you are looking for.

manish_vickey93 + 1 comment But count for 73 should be 1 right? I am not at all getting the question mentioned. Please guide me. Thanks

pillarz_nikolett + 0 comments I just figured it out too. Your output should represent the counters like this: On the first index you must count how many of that index (which is 0 in this case) occurs in the given array. On the second index you must count how many 1 occurs in the given array. And so on :) I hope this helps, I couldn't understand this sentence either at first "The output states that 0 appears 0 times, 1 appears 2 times, 2 appears 0 times, and so on in the given input array."

Hari102 + 0 comments int main() { int n; cin >> n; int b[100]={0}; for(int i = 0; i < n; i++){ int x; cin >> x; b[x]++; } for(int i=0;i<100;i++){ cout<<b[i]<<" "; } return 0; }

mixin + 0 comments This is really bad use of test cases. How are you going to have a test case that accepts output for when there are 0 occurances of a value (example test case), but then every other test case doesn't accept outputs with 0 occurances of values??? I've passed the challenge and at the same time I failed the example test case. What's the point of that?

uphaar23dubey + 0 comments The count of 73 should be 1? please clear my doubt

muditagrawal + 1 comment Using python 3.

n = int(input()) l = [0]*100 for i in map(int,input().split()): l[i]+=1 print(*l)

saurabh_jain_cs1 + 1 comment could you please explain 2nd line of your code

muditagrawal + 0 comments Its a python shorthand for creating a array of length 100 with value at each index as 0.

Sort 204 Discussions, By:

Please Login in order to post a comment