Skip to content

Instantly share code, notes, and snippets.

@NamrataSitlani
Created September 5, 2020 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NamrataSitlani/f55a50a8741ec68f50ffa38c94009699 to your computer and use it in GitHub Desktop.
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.
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