BudiBadu Logo
00:00

Glow Market Profit Planner

Dynamic Programming Medium 2 views

The glow market on the waterfront opens nightly, and each evening's token price for a lantern bundle is logged in advance. Merchants may buy at most one bundle per night and hold any number of bundles, but whenever they sell, the festival charter requires a one-night cooldown before buying again so the market can stabilize. The coordinator wants to know the maximum profit achievable over the season when every buy must be paired with a later sale, and the cooldown rule is respected. No partial bundles may be traded, and all transactions use the published nightly prices.

You receive an array of integers representing bundle prices on consecutive nights. Buying or selling costs exactly the nightly price, and you may hold at most one bundle at a time to keep logistics simple. Skipping nights is allowed, and if the array is empty or the market never rises, the optimal profit is zero. Use dynamic programming to evaluate the best action sequence while leaving the price list unchanged; the coordinator only needs the profit value, not the sequence of trades.

This calculation helps the lantern guild schedule runners, decide when to restock the glow glass kiln, and reassure patrons that nightly showcases remain sustainable. Provide the maximum profit so the guild can commit to supply contracts, book musicians for peak evenings, and plan cooldown nights without risking shortages.

Example 1:

Input: prices = [1,2,3,0,2]
Output: 3
Explanation: Buy on day 1, sell on day 3, cooldown day 4, buy day 4, sell day 5.

Example 2:

Input: prices = [2,1,4]
Output: 3
Explanation: Buy on day 2 and sell on day 3 after waiting through the first decline.

Example 3:

Input: prices = []
Output: 0
Explanation: No trading nights yield zero profit.

Related Problems

No related problems found

Comments (0)

Join the Discussion

Share your thoughts, ask questions, or help others with this problem.

BudiBadu Logo

Glow Market Profit Planner

Dynamic Programming Medium 2 views

The glow market on the waterfront opens nightly, and each evening's token price for a lantern bundle is logged in advance. Merchants may buy at most one bundle per night and hold any number of bundles, but whenever they sell, the festival charter requires a one-night cooldown before buying again so the market can stabilize. The coordinator wants to know the maximum profit achievable over the season when every buy must be paired with a later sale, and the cooldown rule is respected. No partial bundles may be traded, and all transactions use the published nightly prices.

You receive an array of integers representing bundle prices on consecutive nights. Buying or selling costs exactly the nightly price, and you may hold at most one bundle at a time to keep logistics simple. Skipping nights is allowed, and if the array is empty or the market never rises, the optimal profit is zero. Use dynamic programming to evaluate the best action sequence while leaving the price list unchanged; the coordinator only needs the profit value, not the sequence of trades.

This calculation helps the lantern guild schedule runners, decide when to restock the glow glass kiln, and reassure patrons that nightly showcases remain sustainable. Provide the maximum profit so the guild can commit to supply contracts, book musicians for peak evenings, and plan cooldown nights without risking shortages.

Example 1:

Input: prices = [1,2,3,0,2]
Output: 3
Explanation: Buy on day 1, sell on day 3, cooldown day 4, buy day 4, sell day 5.

Example 2:

Input: prices = [2,1,4]
Output: 3
Explanation: Buy on day 2 and sell on day 3 after waiting through the first decline.

Example 3:

Input: prices = []
Output: 0
Explanation: No trading nights yield zero profit.

00:00
Loading editor...
Test Results

Run your code to see test results

Click the Submit button to execute your solution

Related Problems

No related problems found

Comments (0)

Join the Discussion

Share your thoughts, ask questions, or help others with this problem.