title: given a series of stock prices in an array. Pick when to buy and when to sell to gain max profit
body: <p>given a series of stock prices in an array. Pick when to buy and when to sell to gain max profit.
  from one website i got something like this-ef maxprofit(prices):</p>
  
  <blockquote>
    <p>buydate, selldate = 0, 0</p>
    
    <p>maxprof = 0 minprice = prices[0] mindate = 0</p>
    
    <p>for d, p in enumerate(prices[1:]): if p &lt; minprice: minprice = p
    mindate = d + 1 continue</p>
    
    <p>prof = p - minprice</p>
    
    <p>if prof > maxprof: maxprof = prof buydate, selldate = mindate, d + 1</p>
    
    <p>return (buydate, selldate), maxprof</p>
  </blockquote>
  
  <p>but i think..we should consider negative prices too..isn't? any other solution or comments are most welcome</p>