Best Time to Buy and Sell Stock II
Updated
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[]) → intExamples
Example 1
prices = [7,1,5,3,6,4]return = 7Take the rises from one to five and from three to six.
Example 2
prices = [1,2,3,4,5]return = 4The entire increasing run yields four.
Constraints
0 <= prices.length <= 1000000 <= prices[i] <= 100000
More Point72 interview questions
- Find Minimum in a Rotated Sorted ArrayPHONE SCREEN · Seen Aug 2026
- Generate an Optimal Portfolio Trading ReportPHONE SCREEN · Seen Apr 2026
- Maximize Array Beauty After DeletionsOA · Seen Aug 2026
- Simulate a Deterministic Finite AutomatonOA · Seen Aug 2026
- Initial Public OfferingOA · Seen Jul 2026
- Test the HypothesisOA · Seen Jul 2026
- Get Triplet CountOA · Seen Jul 2026
- Internet Service Provider Monthly ReportOA · Seen Jul 2026
- Server SelectionOA · Seen Jul 2026
- Lexicographically Smallest String After Substring OperationOA · Seen May 2026
Similar questions at other companies
- Best Stock Trade with Buy and Sell DaysGoogle · PHONE SCREENGoogle interview questions
- Can Place FlowersAgoda · PHONE SCREENAgoda interview questions
- Maximum Later Checkpoint Altitude GainYellow.ai · PHONE SCREEN
- Assign CookiesAmazon · PHONE SCREEN
- Maximum Profit with Exactly One Stock TransactionRetool · PHONE SCREEN · ONSITE INTERVIEWRetool interview questions
- Best Time to Buy and Sell StockOracle · PHONE SCREEN · ONSITE INTERVIEWOracle interview questions
- Best Time to Buy and Sell StockJP Morgan Chase · PHONE SCREENJP Morgan Chase interview questions
- Choose the Front Football TeamAnduril · PHONE SCREENAnduril interview questions
- Best Time to Buy and Sell StockBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Best Time to Buy and Sell StockHeadlands Technologies · PHONE SCREEN · ONSITE INTERVIEWHeadlands Technologies interview questions