You are given an array arr where each element represents the cost of a stock on a particular day. Your task is to determine the maximum possible profit you can achieve by buying and selling the stock multiple times.
Note:
You can only sell a stock that you have previously bought.
You cannot hold more than one stock at a time on any given day.
Topics
Companies
Articles
Examples:
Expected Time Complexity: O(n)
Expected Auxiliary Space: O(n)
Constraints:
2 = arr.size() = 10^6
0 = arr[i] = 10^6
Companies:
AmazonMicrosoftSamsungWalmartOracle + 5 more
Topics:
ArrayDynamic Programming
Please log in to access the Submissions tab, where you can review your progress and explore code submissions from other participants.
Please log in to access the Solution tab and view detailed answers and explanations.
Please log in to access the Discussion tab and join conversations with other participants.
Access Restricted: Please Login to access the code editor and test cases.