Quant Memo
Coding/●●●●●

Sort a nearly-sorted tick stream

Timestamps arrive almost in order: each is at most k positions away from where it belongs in the fully sorted stream (network jitter shuffles nearby ticks). Sort the stream efficiently, exploiting the small displacement.

stream = [2, 1, 3, 4], k = 1
-> [1, 2, 3, 4]

Return the sorted stream. Aim for O(nlogk)O(n \log k) time and O(k)O(k) space.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions