MaxProfit

It is an easy exercise. The key point is making clear what you want to know during the iterating of the Array. In this question, the keys are current lowest point and current max profitAn array A consisting of N integers is given. It contains daily prices of a stock share for a period of N consecutive days. If a single share was bought on day P and sold on day Q, where 0 ≤ P ≤ Q < N, then the profit of such transaction is equal to A[Q] − A[P], provided that A[Q] ≥ A[P]. Otherwise