Solution to Stock Maximization from HackerRank