This question evaluates algorithmic problem-solving skills, particularly efficient array processing and profit-optimization across single-transaction and multiple-transaction variants, along with time and space complexity analysis.
You are given an integer array prices where prices[i] is the price of a stock on day i (0-indexed).
Answer the following two subproblems:
0
.
Assume:
1 <= n <= 10^5
, where
n
is the length of
prices
.
0 <= prices[i] <= 10^4
.
Design efficient algorithms for both subproblems and analyze their time and space complexity.