human
Maximize Profit by trading stocks based on given rate per day | Function to find the maximum profit.
Start from the last day.
Traverse and keep adding the profit until a day with price of stock higher than currentDay is obtained.
Set this day as currentDay with maximum cost of stock currently.
Return the profit.
Given array of prices.
Function call"
How can the above be solved in Python?
 What is a code to maximize Profit by trading stocks based on given rate per day and the other steps required?
assistant
#Here is code to maximize Profit by trading stocks based on given rate per day and the other steps required.
 def maxProfit ( prices , n ) :
	profit = 0
	currentDay = n - 1
	while ( currentDay > 0 ) :
		day = currentDay - 1
		while ( day >= 0 and ( prices [ currentDay ] > prices [ day ] ) ) :
			profit += ( prices [ currentDay ] - prices [ day ] )
			day -= 1
		currentDay = day ;
	return profit ;
prices = [ 2 , 3 , 5 ]
N = len ( prices )
print ( maxProfit ( prices , N ) )