InterviewLegend

Heaps, Top-K & Intervals

Alex Chen22 min read169 real interview reports

Everything X shows you is ranked. The timeline picks a few hundred posts out of the thousands your follows produced. Trending surfaces the hottest hashtags of the last hour. A dashboard reports the median latency of a live request stream. Underneath all of it sit three plain moves this family drills. A heap pulls the extreme of a set without ordering the rest. Two heaps run back to back to track the running middle of a stream. And sorting then sweeping folds a pile of overlapping time windows into a tidy few. None of the three is exotic, which is exactly why the loop expects them to be automatic.

The pressure X applies here is the pressure it applies everywhere in the coding loop. The code has to run and clear the cases on a shared editor, you reach for the edges without being told, and you give a spoken read of the time and space. That holds across both versions of the company: the earlier Twitter screen still live on some roles, and the harder xAI-run bar that came with the merger. Reports vary on the exact rounds. What stays constant is that a clean heap you can write without fumbling buys the room for the follow-up that almost always lands next.

The X angle
Every problem here is a scale model of something ranking your feed right now. The kth largest engagement score is the cutoff a post has to beat to make a top-k shelf, the same threshold trending computes over a firehose of hashtags. The running median is how a live dashboard reports the p50 of an engagement or latency stream without re-sorting on every event. Coalescing overlapping windows is what a rate limiter and a trending pipeline both do when they fold bursts of activity into the spans that matter. Build the small version cleanly and you have shown the shape of the real one.
What's inside
  • 3 problems, worked step by step
  • about 22 min

Premium lessonX (Twitter) interview guide

These took digging.

What candidates walked out with, from 20,000+ reports, forum threads behind logins and write-ups in Chinese. Then solved step by step.

100 companies. Checked every month.

Unlock all 100 companies

$49 a year · less than $1 a week · Cancel anytime

Had your X (Twitter) interview?Tell us what they asked. Reviewed before it goes in, never with your name.
X (Twitter) interview guide

Know what X (Twitter) asks before you walk in.

19 coding · 5 system design · 20 behavioral questions

Get Premium$49 a year · Cancel anytime
Or start freeNo card.

Get their questions first.

InterviewLegend is independent and not affiliated with or endorsed by any company it covers.