AO
Back

Merge K Sorted Feeds (Cumulative Price Variant)

Phone ScreenPhone ScreenLast reported September 2026Medium Frequency

Problem Overview

You are given K data feeds. Each feed is a list of events sorted by timestamp, and each event is (timestamp, price_delta). Merge all the feeds in timestamp order and, after each event, output the cumulative price: it starts at 0 and each event adds its delta.

feeds = [
    [(1, 5), (4, -2)],        # feed 0
    [(2, 3), (4, 1)],         # feed 1
    [(3, -1)],                # feed 2
]
cumulative_prices(feeds)
-> [(1, 5), (2, 8), (3, 7), (4, 5), (4, 6)]
#   at t=4, feed 0's event comes before feed 1's

Rules from the most detailed report (clarify them with your interviewer, who asked about edge cases in detail):

  • Two feeds with events at the same timestamp: the lower feed index goes first; within one feed, the original order is kept.
  • Deltas can be negative, so the price can go below zero.
  • Empty feeds are skipped.

Variants reported

  • One report describes a LeetCode 23 variant in which entries with the same timestamp are merged first, then the whole array. It does not say what that means for the output; if you get it, ask.
  • Several reports got the classic version: merge K sorted arrays into one. One of those added a constraint: no divide-and-conquer merging, and O(k) space instead of O(n).
  • One phone screen wrapped the classic merge in a C++ abstract class, with every array and object inside a shared_ptr.

Follow-up Arc

Interviewers escalate through these phases. The order varies, but most candidates see at least one from each bucket.
Trade-off discussion · 4
Trade-off discussion

How do you handle events with the same timestamp in different feeds?

Probes for: Price-feed variant

What if a price delta is negative, or a feed is empty?

Probes for: Price-feed variant

Merge the lists without divide-and-conquer merging, in O(k) space instead of O(n).

Probes for: Classic variant

What is the time complexity, and can you explain your core code?

Probes for: C++ object-oriented variant

Approach Trade-offs

Approaches actually attempted in reports — including ones that lost candidates time. Pick deliberately.
ApproachNotes
Divide-and-conquer pairwise mergeRuled out in one report, which asked for O(k) space instead of O(n); with array inputs the intermediate merged arrays take O(n) space.

What Reports Emphasize

Common mistakes: Spending a long time reading the provided C++ abstract class and shared_ptr template code before starting the algorithm; Unfamiliarity with shared_ptr usage in C++, which cost time in the object-oriented variant

Interviewer hints: In the C++ object-oriented variant, the interviewer patiently helped the candidate understand the shared_ptr code structure; In the price-feed variant, the interviewer probed edge cases in detail; the candidate advises asking about them very clearly

What passers do: In the C++ object-oriented variant, the candidate worked through the template code with the interviewer's help, wrote the algorithm smoothly, and moved on to the next round

Edge cases probed: Events with the same timestamp across feeds (tie rule: feed index, then original order); Negative price deltas; Empty feeds

Practice

Write your own against 7 test cases, or read the worked solution — approach, complexity, and code that runs.

Prepping for Citadel with friends?

Send them this page. It is free to read, no account needed.

More Citadel Questions

Free preview

Every question in the Citadel catalog gets this depth

What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 62 Citadel questions, refreshed monthly from new candidate reports.

$59/mo — or $50/mo with the 3-month pass · cancel anytime
Citadel · Phone Screen · Reported 6× across candidate reports
Is this helpful?