title: Recursive Stock Maximization
body: <p>The problem is to maximize the profit of a stock given the prices of stock on a given day.
  I can buy only 1 stock, sell any number or do nothing.</p>
  
  <pre><code>Test cases:
  Input: 1 2 100
  Output: 197
  Explanation: Bought on day 1 and day 2 sold on day 3 total profit = (100 - 1) + (100 - 2) = 197
  
  Input: 1 3 1 2
  Output: 3
  Explanation: buy one share on day 1, sell one on day 2, buy one share on day 3, and sell one share on day 4.
  </code></pre>
  
  <p>I have a recursive solution below and I know there are other solutions but I am trying to build on from a recursive one:</p>
  
  <pre><code>int maxProfit(vector&lt;int&gt; stock)
  {
      int profit = helper(stock, stock[0], 1, 1);
      return profit &lt; 0 ? 0 : profit;
  }
  
  int helper(vector&lt;int&gt;&amp; stock, int cost, int index, int stockcount)
  {
      if (index == stock.size() - 1)
      {
          return (stock[index] * stockcount) - cost;
      }
      int buy = helper(stock, cost + stock[index], index + 1, stockcount + 1);
      int sell = helper(stock, cost - stock[index], index + 1, stockcount - 1);
      return max(buy, sell);
  }
  </code></pre>
  
  <p>Is the algorithm a correct recurisve approach and is there a way I can memoize the above? possibly removing the accumulator <code>cost</code>?</p>