implemented max stock price algorithm in O(n) time