I was also asked the stock purchase question.
Sigiloso
I got the n2 answer reasonably quickly. Really struggled with the optimization though. Never did have an insight on an n complexity solution. Had an idea for an nlogn solution, though the implementation details were still in a pretty sketchy state when the time ran out.