Counting Sort 1

  • + 15 comments

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

    • + 2 comments

      i missed that in first submission :p

      • + 0 comments

        Full python solution.

        Hackerrank - Counting Sort 1 Solution

      • + 0 comments

        here is problem solution in java python c++ c and javascript programming. https://programs.programmingoneonone.com/2021/04/hackerrank-counting-sort-1-solution.html

    • + 0 comments

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

    • + 2 comments

      Hey, I dont understand the problem statement.Can you please elaborate

      • + 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 :).

      • + 1 comment

        Go through this simple code

        include

        include

        using namespace std ;

        int main(){

        int n ,index;
        vector<int> indexCount(100) ; 
        cin>>n;
        
        for(int x = 0 ; x<n ; x++){
            cin>>index ; 
            indexCount[index]++ ;
        }
        
        for(int x=0;x<100;x++){
            cout<<indexCount[x]<<" ";
        }
        
        
        
        return 0  ;
        

        }

    • + 0 comments

      i submitted like 10 times ..then i saw your comment :P ..thanks

    • + 1 comment

      Thanks, hackerrank catched me)

      • + 0 comments

        caught*

    • + 0 comments

      Liteally every one gets stuck here!

    • + 0 comments

      Thanks a lot

    • + 0 comments

      And here I already submitted it 5 times. Thank you man.

    • + 0 comments

      Thanks I missed that too in first submission!

    • + 0 comments

      lol my god thanks dude

    • + 0 comments

      but why only 0 to 100?

    • + 0 comments

      This one comment woke me up after re-running my code 7 times, with various logics to optimize the running time. Will try to be more open-minded 😕

    • + 0 comments

      okay , but why what is the difference ?

    • + 0 comments

      Thanks!!

    • + 0 comments

      Thanks man solved my issue solution in js https://jsbin.com/lajiqekako/1/edit?js,console