HackerRank Maximizing Stock profit