Maximizing profit for given stock quotes
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 given the stock prices for a set of days . Each day, you can either buy one unit of stock, sell any number of stock units you have already bought, or do nothing. What is the maximum profit you can obtain by planning your trading strategy optimally?** Examples ( The input i.e the no of days can vary ) 5 3 2 => profit = 0 // since the price decreases each day ,the max profit we can make = 0 1 2 100 => profit = 197 1 3 1 2 =>profit = 3 // we buy at 1