Array Transform

Whats wrong with my logic or code i am constantly getting a WA inspite of checking the code for many test case…

#include<stdio.h>

int ans(int n, int k)
{
    int i,mod1,mod2,f1=0,f2=0;
    int ele;
    int flag=0;
    scanf("%d",&ele);
    mod1=ele%(k+1);
    f1++;
    for(i=1;i<n;i++)
    {
        scanf("%d",&ele);
        if((ele%(k+1))==mod1)
            f1++;
        else if(flag==0)
        {
            mod2=ele%(k+1);
            flag=1;
            f2++;
        }
        else if((ele%(k+1))==mod2)
            f2++;
        else return 0;
    }
    if(f1>1&&f2>1)
        return 0;
    else return 1;
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,k;
        scanf("%d",&n);
        scanf("%d",&k);
        if(ans(n,k)==0)
            printf("%s\n", "NO");
        else printf("%s\n","YES");
    }
    return 0;
}

in your ans function. you have a return 0 in your for loop.

it is clear you won’t read the remaining numbers of the current test case.

it leads to WA.

3 Likes

Delete Tubi tv account is easily delete for our App for the profile to chaneging process availble for free of cost, Tubi TV Reviews Here

//