Reported March 2024
IBMgreedy

Latest K Requests

Reported by candidates from IBM's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live IBM OA. Under 2s to a working solution.
Founder's read

IBM's March 2024 OA included a greedy problem asking you to track the latest K requests. You're given a stream of timestamps and need to return the K most recent ones, often with constraints on how fast you can process them. This isn't a trick question, but the greedy choice (always keep the most recent K) is easy to mess up if you're not careful about your data structure. StealthCoder can feed you the pattern and code template instantly if you freeze up on the live OA.

Pattern and pitfall

The core pattern is greedy: maintain a window of exactly K requests, always discarding the oldest when a new one arrives. The tricky part isn't the algorithm, it's the implementation. Most candidates reach for a set or unsorted array and then get burned on the "find minimum" or "remove minimum" step. A min-heap lets you pop the oldest in O(log K) time per request. If K is small and the total request count is large, heap-based greedy shines. Watch for edge cases: what if fewer than K requests arrive? What if requests have tied timestamps? The greedy logic still holds, but your tie-breaking must be explicit. StealthCoder sees the heap setup in seconds and can guide you past the indexing bugs.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Latest K Requests cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as sliding window maximum. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass IBM's OA.

IBM reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Latest K Requests FAQ

Is this a heap problem or can I solve it another way?+

Yes, you can use any structure that lets you find and remove the minimum quickly. Heap is O(log K) per op. Sorted list is O(K) per deletion. For K under 100, either works. Over 1000 requests, heap beats naive approach. Greedy is the pattern either way.

What's the trick IBM is testing here?+

They want to see if you pick the right data structure under time pressure. The greedy logic is obvious. The mistake is using a naive structure (like a list) and doing O(K) deletions repeatedly. Show you understand the cost tradeoff and you're golden.

Do I need to handle tie-breaking if two requests have the same timestamp?+

Depends on the exact problem statement. If it's not specified, assume order doesn't matter among tied timestamps. If it does, use (timestamp, request_id) as your sort key. Check the problem wording carefully before you code.

How much time should I spend designing vs. coding?+

Two minutes to sketch the heap approach. Five minutes to code. Five minutes to test on the sample. If you're stuck on the data structure choice after two minutes, ask for clarification. Don't waste time on a wrong approach.

Is this easier or harder than typical greedy problems?+

Easier conceptually, harder in execution. The greedy choice is obvious, but the heap implementation trips people up. If you've coded a heap recently, you'll be fine. If not, you might stub your toe on heap ops.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with IBM.

OA at IBM?
Invisible during screen share
Get it