Best Time to Buy and Sell Stock
Walk the array once, keep the lowest price so far, and compute the best profit if you sold today.
Find the maximum profit from one buy and one sell of a stock price series.
Tagged with greedy
Walk the array once, keep the lowest price so far, and compute the best profit if you sold today.
Find the maximum profit from one buy and one sell of a stock price series.
Track a running candidate and increment or decrement a counter as you scan. When the counter drops to zero, start fresh with the current value as the new candidate.
Return the element that appears more than n // 2 times in an array.