As reported: D. E. Shaw SMTS code pair 1 (2025): after an introduction, Best Time to Buy and Sell Stock II and then III; the expectation was to explain the solution and run test cases.
This is LeetCode 122 — Best Time to Buy and Sell Stock II. Our write-up: /best-time-to-buy-and-sell-stock-ii.
prices[i] is the price of a stock on day i. Each day you may buy and/or sell, holding at most one share at any time (you may buy and sell on the same day). Return the maximum profit.
Example 1
prices = [7,1,5,3,6,4]
Output: 7
Buy at 1, sell at 5 (+4); buy at 3, sell at 6 (+3).
Example 2
prices = [1,2,3,4,5]
Output: 4
Example 3
prices = [7,6,4,3,1]
Output: 0
Constraints: 1 ≤ prices.length ≤ 3 · 10^4; 0 ≤ prices[i] ≤ 10^4.
Code runner format: one JSON value per line: prices. Implement maxProfit(prices).