Stock Maximum Profit
Problem Overview
- Given stock prices and profits over n days, select i<j<k with price[i]<price[j]<price[k] to maximize profit[i]+profit[j]+profit[k]; return -1 if none.
- Input: price[n], profit[n]; Output: maximum total profit as a long integer.
- Constraints: 1<=n<=4000; values up to 1e9.
- Real-world context: analyze stock trends to choose a profitable 3-day sequence.
- From IBM interviews; a common coding interview interview question problem.
Example
Unlock to view complete problem details
and practice with sample input/output
Was this article helpful?
View Test Cases & Run Code requires membership
Input Variables
Execution Result:
