why is my code for comparing the triplet ,hackerman problem , exceeding the time limit for some test cases?

Viewed 14
int* compareTriplets(int a_count, int* a, int b_count, int* b, int* result_count) 
{
    *result_count=2;
    int *r=(int*)calloc(2,sizeof(int));
    int i;
    i=0;
    while(i<3)
    {
        if(a[i]>b[i])
        {
            r[0]+=1;
        }
        else if(a[i]<b[i])
        {
            r[1]+=1;
        
        }
        else
        {
            continue;
        }
        i++;
    }
return r;
}

'a and b are two array pointers pointing to two array.if element at ith position of either array is greater than the other then one is incremented for the respective array in the new array r.the first position of r array is for a array and second poasition is for b array'

1 Answers

If in a test case, a[i] == b[i], then the else statement is reached, where you continue to the next loop iteration, without getting to i++. This causes an infinite loop.

Related