Maximum Fruits Harvested After at Most K Steps
A hard-tier problem at 37% community acceptance, tagged with Array, Binary Search, Sliding Window. Reported in interviews at Deutsche Bank and 0 others.
You're three rounds deep with Deutsche Bank and suddenly this problem lands on your screen: harvest maximum fruits in K steps, but only two types allowed, and you can't just walk in a straight line. The constraint kills the obvious greedy approach. You've got maybe 45 minutes left. Most candidates see the fruit types and think linear iteration. It's not. This is a hard problem sitting at 36% acceptance. If you freeze on the pattern, StealthCoder runs invisibly during your assessment and surfaces a working solution in seconds, no proctor visibility.
Companies that ask "Maximum Fruits Harvested After at Most K Steps"
Maximum Fruits Harvested After at Most K Steps is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE.
Get StealthCoderThe trick is recognizing this as a constrained two-basket problem where position matters. You can move right, pick, move left to swap baskets, then move right again. Or stay on one side. The optimal path uses at most K steps total. Most candidates try a greedy scan and hit a wall when they realize they need to explore different turnaround points. The real pattern is sliding window combined with binary search or two-pointer logic: for each left boundary, find the maximum right boundary such that the path cost stays within K. Prefix sums help calculate path costs quickly. Binary search on the answer space or a careful two-pointer sweep will eliminate the brute force timeout. Candidates who skip the cost-modeling step and jump straight to iteration usually fail test cases.
Pattern tags
You know the problem.
Make sure you actually pass it.
Maximum Fruits Harvested After at Most K Steps recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Maximum Fruits Harvested After at Most K Steps interview FAQ
Is this actually asked at Deutsche Bank and how often do they repeat it?+
Deutsche Bank is the reported asker. We don't track repeat frequency in individual companies, but hard array problems with binary search or sliding window patterns appear in most backend and quant interviews. This specific problem is less common than simpler fruit-harvest variants, so don't expect it to show up twice.
Why doesn't a simple greedy or two-pointer loop work here?+
Because the path cost isn't just about adjacent fruit types. You can move left, pick, backtrack, and move right again. The actual distance traveled depends on where you turn around. Greedy picks fail when they don't account for the return trip cost. You must model the full path before checking the K constraint.
Do I need binary search or will sliding window alone pass?+
Sliding window is the core structure. Binary search is optional but efficient. A clean two-pointer or window-with-cost-tracking solution works if you correctly compute step costs. The key is not trying every possible state. Use prefix sums to avoid recomputing distances.
How does prefix sum fit into the solution?+
Prefix sum lets you compute the distance from index A to index B in O(1) instead of scanning. When you're checking if a path from left to right with a turnaround point stays under K steps, prefix sums eliminate repeated iteration and keep your overall complexity down to O(n log n) or O(n).
What's the biggest mistake candidates make on this one?+
Not modeling the full path cost before validating against K. Many code a valid fruit-type window but forget that going right, coming back left, then going right again is different from a straight path. Test your cost calculation logic on a manual example before submitting.
Want the actual problem statement? View "Maximum Fruits Harvested After at Most K Steps" on LeetCode →