Interview Query

Buy or Sell

Upvote
19
Downvote
Save
Mark Completed
Have you seen this question before?

1. Given a list of stock_prices in ascending order by datetime, and their respective dates in list dts, write a function max_profit that outputs the max profit by buying and selling at a specific interval.

Example:

Input:

stock_prices = [10,5,20,32,25,12]
dts = [
    '2019-01-01', 
    '2019-01-02',
    '2019-01-03',
    '2019-01-04',
    '2019-01-05',
    '2019-01-06',
]

def max_profit(stock_prices,dts) -> 27

2. Now, to make it harder, given the list of stock prices and date times in ascending order by datetime, write max_profit to output the profit and start and end dates to buy and sell for max profit.

Example:

Input:

def max_profit(stock_prices, dts) -> 
(27, '2019-01-02', '2019-01-04')
Next question: Comment Upvotes
.....
Python 3.9.6
Loading editor
Use Shift + Enter to run code

Comments

Loading comments