Problem 49

6 comments on “Problem 49”


  • sunny

    python:
    def fun(arr):
    arr2=[]
    for i in range(0,len(arr)):
    for j in range(i+1,len(arr)):
    if (arr[i] == arr[j]):
    s=j-i
    arr2.append(s)
    if (len(arr2) == 0):
    print(-1)
    else:
    print(min(arr2))

    arr=list(map(int,input().split()))
    fun(arr)


  • shushank

    #Python Programming

    l=list(map(int,input().split(” “)))
    l1=[]
    for i in range(1,len(l)):
    a1=l[i]
    for j in range(0,i):
    b1=l[j]
    if a1==b1:
    l1.append(abs(j-i))
    print(min(l1))


  • goutham

    #include
    using namespace std;
    int main()
    { int mindis=-1;
    int a[]={1,2,3,4,5,6,7,8,9};
    int i,j,n;
    n=sizeof(a)/sizeof(a[0]);
    for(i=0;i<n-1;i++)
    {for(j=i+1;j(j-i-1))
    {mindis=j-i-1;}
    }
    }
    }
    cout<<mindis;
    return 0;
    }


  • TADEPALLI

    #include
    #include
    #include
    int main()
    {
    int n,i,j,min=INT_MAX;
    scanf(“%d”,&n);
    int arr[n],freq[n];
    for(i=0;i<n;i++)
    {
    scanf("%d",&arr[i]);
    freq[i]=0;
    }
    for(i=1;i=0;j–)
    {
    if(arr[i]==arr[j])
    {
    freq[j]=abs(i-j);
    }
    }
    }
    for(i=0;i<n;i++)
    {
    if(freq[i]==0)
    continue;
    if(freq[i]<min)
    min=freq[i];
    }
    if(min==INT_MAX)
    printf("%d",-1);
    else
    printf("The difference is %d\n",min);
    return 0;
    }