I have written a code to solve the Maximize Stock Trading Profit Challenge
Maximize Stock Trading Profit: Maximize Stock Trading Profit | Codecademy
It is able to pass 2 test cases but I want to understand what the other 3 test cases my code is not able to account for.
Below is my code.
def max_profit_days(stock_prices):
# Write your code here:
sell_day = 0
buy_day = 0
least_to_greatest = sorted(stock_prices)
greatest_to_least = sorted(stock_prices,reverse=True)
for price in stock_prices:
if price == least_to_greatest[0]:
sell_day += stock_prices.index(price)
elif price == greatest_to_least[0]:
buy_day += stock_prices.index(price)
return (sell_day, buy_day)