As reported: Amazon SDE-2 (Alexa), face-to-face bar raiser round (Dec 2025): two DSA problems, this one first, with full working code and a dry run, plus Leadership Principle questions.
You are given an integer k and an array prices where prices[i] is the price of a stock on day i. Find the maximum profit you can make with at most k transactions (a transaction is one buy followed by one sell). You may not hold more than one share at a time: you must sell before you buy again.
This is LeetCode 188 — Best Time to Buy and Sell Stock IV.
Example 1
k = 2, prices = [2,4,1]
Output: 2 buy at 2, sell at 4
Example 2
k = 2, prices = [3,2,6,5,0,3]
Output: 7 buy 2 sell 6 (+4), buy 0 sell 3 (+3)
Constraints: 1 ≤ k ≤ 100; 1 ≤ prices.length ≤ 1000; 0 ≤ prices[i] ≤ 1000.
Code runner format: two lines: k, then prices as a JSON array. Implement maxProfit(k, prices); the harness prints the profit.