Best Time to Buy and Sell Stock IV
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given an integer k and an array prices, where prices[i] is the price of a given stock on day i.
Your goal is to maximize the total profit you can earn by completing **at most** k transactions. A single transaction consists of buying the stock on one day and later selling it on a strictly later day.
You may not hold more than one share of the stock at a time, which means you must sell the share you are holding before you can buy again. You also cannot buy and sell on the same day.
Return the maximum profit achievable. If no profitable sequence of transactions exists, return 0 (you may simply choose to make no transactions).
Examples
Constraints
- `0 <= k <= 100`
- `0 <= prices.length <= 1000`
- `0 <= prices[i] <= 1000`
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.