FastPrepMerge Price-Delta Feeds

Merge Price-Delta Feeds

Citadel logoCitadelMediumNEW GRADPHONE SCREEN
Learn

Problem statement

You are given feeds, where each feed is a list of events sorted by nondecreasing timestamp. An event is [timestamp, delta].

Merge all events in chronological order. For equal timestamps, process the lower feed index first; events tied within one feed retain their original order. Start the absolute price at 0. After processing each event, add its delta to the price and append the new price to the result. Deltas and the running price may be negative. Empty feeds are allowed.

Function

mergePriceFeeds(feeds: int[][][]) → int[]

Examples

Example 1

feeds = [[[1,5],[4,-2]],[[1,3],[3,7]],[]]return = [5,8,15,13]

The equal timestamp-1 events use feed order, followed by timestamps 3 and 4.

Example 2

feeds = [[],[[2,-4],[2,1]]]return = [-4,-3]

Within one feed, equal-time events preserve source order.

Constraints

  • 0 <= feeds.length <= 10000.
  • The total number of events is at most 200000.
  • Each event has exactly two integers.
  • Each feed is sorted by timestamp.
  • All intermediate prices fit in a signed 32-bit integer.

More Citadel problems

See Citadel hiring insights
public int[] mergePriceFeeds(int[][][] feeds) {
    // Write your code here.
}
feeds[[[1,5],[4,-2]],[[1,3],[3,7]],[]]
expected[5,8,15,13]
Checking account…