include <stdio.h>
int main()
{
int t, x, y, count;
scanf(“%d”, &t);
while(t–)
{
scanf(“%d %d”, &x, &y);
count=0;
while(x!=y)
{
if(x>y) y+=2;
else x+=1;
count++;
}
printf(“%d\n”, count);
}
return 0;
}
int main()
{
int t, x, y, count;
scanf(“%d”, &t);
while(t–)
{
scanf(“%d %d”, &x, &y);
count=0;
while(x!=y)
{
if(x>y) y+=2;
else x+=1;
count++;
}
printf(“%d\n”, count);
}
return 0;
}
Here you are using too many loops in the code, i.e.,
Time complexity : O(n^2)
Send the problem link to the question
so we can give you a more appropriate answer.
//rest of the code
if(x>y)
y+=2
else
x+=1
count++
//rest of the code
this could be correct , check whether the count increment operation should be within the else block or outside the else block.