Program to Find 2 Elements in the Array such that Difference between them is Largest

a=list(map(int,input().split()))
diff=a[1]-a[0]
minele=a[0]
for i in range(1,len(a)):
    if a[i]-minele>diff:
        diff=a[i]-minele
    if a[i]<minele:
        minele=a[i]
print(diff)



Input

1 5 9 3 4 8


Output
8

No comments:

Post a Comment