I was asked this question while interviewing for a startup and saw this again in the recent contest at
Code Sprint:systems
**The question :
You are
your logic is correct...
sell at global maxima's..but recursion is not required...
if ith element is global maxima...sell all stocks before i!
Now problem reduces to previous answer+ i+1 to N...
recursion is not required...linearly we can calculate!