human
Minimum possible travel cost among N cities | Function to return the minimum cost to travel from the first city to the last.
To store the total cost.
Start from the first city.
If found any city with cost less than that of the previous boarded bus then change the bus.
Calculate the cost to travel from the currently boarded bus till the current city.
Update the currently boarded bus.
Finally calculate the cost for the last boarding bus till the ( N + 1 ) th city.
Driver code"
How can the above be solved in Python?
 ... Can you provide a code to minimum possible travel cost among N cities and the other steps required?
assistant
#Here is code to minimum possible travel cost among N cities and the other steps required.
 def minCost ( cost , n ) :
	totalCost = 0
	boardingBus = 0
	for i in range ( 1 , n ) :
		if ( cost [ boardingBus ] > cost [ i ] ) :
			totalCost += ( ( i - boardingBus ) * cost [ boardingBus ] )
			boardingBus = i
	totalCost += ( ( n - boardingBus ) * cost [ boardingBus ] )
	return totalCost
cost = [ 4 , 7 , 8 , 3 , 4 ]
n = len ( cost )
print ( minCost ( cost , n ) )