Problem · Array

Best Time to Buy and Sell Stock II

Learn this problem
EasyPoint72 logoPoint72FULLTIMEPHONE SCREEN

Problem statement

Given daily prices, return the maximum profit obtainable by any number of buy-then-sell transactions while holding at most one share at a time.

Function

maxProfit(prices: int[]) → int

Examples

Example 1

prices = [7,1,5,3,6,4]return = 7

Take the rises from one to five and from three to six.

Example 2

prices = [1,2,3,4,5]return = 4

The entire increasing run yields four.

Constraints

  • 0 <= prices.length <= 100000
  • 0 <= prices[i] <= 100000

More Point72 problems

drafts saved locally
public int maxProfit(int[] prices) {
  // Write your code here.
}
prices[7,1,5,3,6,4]
expected7
checking account