Problem Submissions Solution

Stock buy and sell

Difficulty: Medium

Acceptance: %

Points: 30.00

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:
Amazon Microsoft Samsung Walmart Oracle + 5 more
Topics:
Array Dynamic Programming
Locked Content
Access Restricted: Please Login to access the code editor and test cases.