Stocks Max profit problem

The below code is working fine for the stocks max profit question, any thoughts if this is an efficient way or could there be a better approach:

x =[7,2.5,13,11,19,11,9,10]
min = 0
max = len(x) -1
y = sorted(x)
while (y[max] > y[min]) and (x.index(y[max]) < x.index(y[min])) :
min = min + 1
print ("max_profit: ",y[max] - y[min])

You have to first buy and then sell. Since you have sorted the array, the order is lost.

Hi Sandeep,
Actually, to avoid this, I assigned the sorted array to another variable y and in the while conditions have used both x and y.
x

Out[8]:

[7, 2.5, 13, 11, 19, 11, 9, 10]

In [9]:

y

Out[9]:

[2.5, 7, 9, 10, 11, 11, 13, 19]

n = int(input("Number of Stock price values: "))
A = input("Enter “+str(n)+” price values with comma separted : ")
A = A.split(’,’)
try :
n == len(A)
for x in range(0,n):
A[x] = float(A[x])
d = 0
buy = 0
sell = 0
maxprofit = 0
for i in range(0,len(A)) :
for j in A:
k = A[i]
if (k > j) and A.index(k) > A.index(j):
d = k - j
if maxprofit < d:
maxprofit = d
buy = j
sell = k
print("Buying Price : ", buy)
print("Selling Price : ", sell)
print("Maximum Profit : ", maxprofit)
except :
print(“Enter the correct number of values”)