Solution for problem [Best Time to Buy and Sell Stock III]