Created
September 5, 2020 18:44
-
-
Save NamrataSitlani/f55a50a8741ec68f50ffa38c94009699 to your computer and use it in GitHub Desktop.
Given an array of numbers that represent stock prices (where each number is the price for a certain day), find 2 days when you should buy and sell your stock for the highest profit.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def stockBuySell(stock_list): | |
buy = stock_list.index(min(stock_list)) +1 | |
sell = stock_list.index(max(stock_list)) +1 | |
return f'buy on day {buy}, sell on day {sell}' | |
if __name__ == '__main__': | |
stock_list = [110, 180, 260, 40, 310, 535, 695] | |
print(stockBuySell(stock_list)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment