Stock trading k transactions

Write codeHard30 minBloomberg and Citadel style

Your task

Given an integer k and daily prices, find the maximum profit with at most k completed transactions, holding at most one share at a time. k can be 0 and can exceed the number of days. The price list may be empty.

Examples

stock_k_transactions(k: int, prices: list[int]) -> int
Example 1
Inputstock_k_transactions(2, [2, 4, 1])
Output2