FastPrepStock Profit With At Most k Trades
Problems/Stock Profit With At Most k Trades

Stock Profit With At Most k Trades

Adobe logoAdobe● HardFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: You find the best total profit from at most k buy-then-sell trades over a list of daily prices. A post by an SDE 2 candidate (August 2023, rejected after the third round) links this classic task as the first item of Round 1. That round also had a tree question and a talk on microservices. The author marks the question as done. The post gives no limits or examples.

The rules are those of the linked task. You hold one share at a time. Each trade sells on a later day than it buys. No trade means a profit of 0. We chose these limits: k up to 100, up to 1000 days, and prices from 0 to 10^4. We wrote new examples.

Our version is about 95% the same as the reported question.

You are given an integer k and an array prices, where prices[i] is the price of a stock on day i.

A trade means buying one share on some day and selling it on a later day. You may make at most k trades, and you can hold at most one share at a time, so a share must be sold before the next one is bought (selling and buying again on the same day is allowed).

Return the largest total profit you can make. If no trade earns money, return 0.

Function

maxProfitWithKTrades(k: int, prices: int[]) → int

Examples

Example 1

k = 2prices = [3,8,2,9,4,10]return = 13

Two trades: buy at 3 and sell at 8 (profit 5), then buy at 2 and sell at 10 (profit 8), for 13. Buying at 2, selling at 9, then buying at 4 and selling at 10 also gives 7 + 6 = 13. Taking all three rises would give 18, but that needs three trades.

Example 2

k = 3prices = [9,7,4,1]return = 0

The price only falls, so every trade would lose money. Making no trade gives 0.

Example 3

k = 1prices = [2,6,1,7,3,9]return = 8

With one trade, buy at the lowest price before the highest later price: buy at 1, sell at 9, profit 8.

Constraints

  • 1 <= k <= 100
  • 1 <= prices.length <= 1000
  • 0 <= prices[i] <= 10^4

More Adobe Phone Screen questions

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
  • Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
  • Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
  • Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
  • Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
  • Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
  • Largest Value in Every Sliding WindowPHONE SCREEN · 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
  • Maximum Profit with at Most K TransactionsTekion · PHONE SCREENTekion interview questions
  • Count Ordered Combination Sums with Negative ValuesPinterest · PHONE SCREENPinterest interview questions

Interview reports that mention this question

  • Adobe SDE and Senior SWE Interviews: 9 Experiences (Part 3 of 6)

Adobe interview experiences

  • Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
  • Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
  • Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
  • Adobe New Grad MTS Interview Questions: 7 Experiences
  • Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)
All Adobe interview questionsSee Adobe hiring insights
Saved
class Solution {
    public int maxProfitWithKTrades(int k, int[] prices) {
        // Write your code here.
    }
}
Checking account…