Maximum Profit with at Most K Transactions
Updated
Problem statement
You are given the price of one batch of goods on consecutive days. You may complete at most k transactions. A transaction consists of buying once and selling later.
- You must sell before buying again.
- You may hold at most one batch at a time.
- A completed buy-and-sell pair counts as one transaction.
Return the maximum profit possible.
Function
maxProfit(prices: int[], k: int) → intExamples
Example 1
prices = [3,2,6,5,0,3]k = 2return = 7Buy at 2 and sell at 6, then buy at 0 and sell at 3.
Constraints
1 <= prices.length <= 10000 <= k <= 1000 <= prices[i] <= 10^6
More Tekion interview questions
- Peak Resource Usage Across Weighted IntervalsPHONE SCREEN · Seen Sep 2026
- Dungeon GamePHONE SCREEN · Seen Sep 2026
- IPOPHONE SCREEN · Seen Sep 2026
- Coin Game From The EndsPHONE SCREEN · Seen Sep 2026
- Open Lockers After Toggle PassesPHONE SCREEN · Seen Sep 2026
- Maximum Concurrent Active LoansPHONE SCREEN · Seen Aug 2026
- Largest Rectangle in HistogramONSITE INTERVIEW · Seen Sep 2026
- Next Greater Element to the RightONSITE INTERVIEW · Seen Sep 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Sep 2026
- Maximum Sum of a Unique-Element SubarrayONSITE INTERVIEW · Seen Jul 2026
Similar questions at other companies
- Split Array to Minimize the Largest SumNation with NaMo · PHONE SCREEN
- Trapping Rain WaterOracle · PHONE SCREENOracle interview questions
- Minimum Length After Removing Arithmetic TriplesMedia.net · PHONE SCREEN
- Select Transactions with Child-Pays-for-Parent PackagesCoinbase · PHONE SCREENCoinbase interview questions
- Longest Consistent Activity StreakAtlassian · PHONE SCREENAtlassian interview questions
- Longest Increasing Path in a MatrixNew Relic · PHONE SCREEN · ONSITE INTERVIEW
- Longest Increasing Subsequence With Bounded Adjacent DifferenceGoogle · PHONE SCREENGoogle interview questions
- Longest Increasing Subsequence With Bounded Adjacent DifferenceAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Count Ordered Combination Sums with Negative ValuesPinterest · PHONE SCREENPinterest interview questions
- Minimum Matrix-Chain MultiplicationsGSA Capital · PHONE SCREEN