• + 0 comments

    Would someone provide a help optimizing the below code? didn't pass test case 6 and test case 8

    int* climbingLeaderboard(int ranked_count, int* ranked, int player_count, int* player, int* result_count) 
    {
       int j=0;
        int rankNoDups[ranked_count];
        for(int i=0;i<ranked_count;++i)     //loop to remove duplication in ranked array
        {
            if(ranked[i]==ranked[i+1])      //look for similar values.
            {
                continue;                   //skip below lines in case of similar values           
            }
            rankNoDups[j]=ranked[i];        //add unique values to rankNoDups array
            j++;    //advance j by one
        }
    
        int count=1;                          //set count to 1
        *result_count=player_count;       //assign value of player_count to *result_count 
        static int a[100000];              //array to stor 
        for(int k=0;k<player_count;++k)        //5,25,50,120  playerrank
        {    
            for(int i=0;i<j;++i)            //100,50,40,20,10   nodups
            {
                if(rankNoDups[i]<=player[k])
                {
                    break;
                }
               count++;
            }
            *(a+k)=count;
           // printf("%d\n",*(a+k));
            count=1;
        }
       //result_count[k]=count;
       //printf(">>>>>>>%d<<<<<<<<",(sizeof(result_count)/sizeof(result_count[0])));
       return a;
    }