Solved Stocks hackerrank problem