As reported: Adobe Computer Scientist 1 loop (Illustrator team, Bangalore, 2025), round 1 (DSA in pseudo code and C++): Best Time to Buy and Sell Stock with its variations II and III, House Robber I and II, and Single Number I and III.
This is LeetCode 122 — Best Time to Buy and Sell Stock II.
prices[i] is a stock's price on day i. You may buy and sell as many times as you like, but you can hold at most one share at a time (selling and buying again on the same day is allowed). Return the largest total profit.
Example 1
prices = [7,1,5,3,6,4]
Output: 7 (buy 1 sell 5, buy 3 sell 6)
Example 2
prices = [1,2,3,4,5]
Output: 4
Constraints: 1 ≤ prices.length ≤ 3·10^4; 0 ≤ prices[i] ≤ 10^4.
Code runner format: one JSON value per line: prices. Implement maxProfit(prices); the harness prints the profit.