This question evaluates algorithmic problem-solving skills with emphasis on array processing, numeric optimization, and time/space complexity analysis in the coding & algorithms domain. It is commonly asked to assess practical implementation ability and efficiency trade-offs under input-size constraints, and the level of abstraction is practical application rather than purely conceptual reasoning.
You are given an integer array prices where prices[i] is the price of a stock on day i.
You may complete at most one transaction: choose a day to buy one share and a later day to sell that share.
Return the maximum profit you can achieve. If no profit is possible, return 0.
prices
: array of integers, length
n
1 <= n <= 2 * 10^5
0 <= prices[i] <= 10^9
prices = [7,1,5,3,6,4]
5
(buy at
1
, sell at
6
)