Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

Boss fightThe Signal Feed

Learn
Play
Prove
Problem context and objectives
Mission briefing

Puzzle systems engineer · A game mechanic is behaving incorrectly

Merge the newest posts from followed authors: The Signal Feed.

Brute force may pass the demo but fail when the world fills with players.

How you win

  1. 1Recognize when Social feed design matches the clues
  2. 2Keep this true after every move: feed candidates come only from the user or currently followed authors
  3. 3Reach the result within O(P log P) simple query, improvable with a heap merge

Rules and pressure

  • Target cost: O(P log P) simple query, improvable with a heap merge
  • State rule: feed candidates come only from the user or currently followed authors
Lesson 1 of 3

Live algorithm trace

Social feed design

Complete execution
1 of 5
0
post 1:5
op
1
follow 1:2
2
post 2:6
3
feed 1
4
unfollow 1:2

User 1 publishes post 5 at the first sequence.

1append each post with increasing sequence
2follow adds an author to the user's set
3unfollow removes that author
4feed includes the user plus current follows
5collect their post candidates
6return at most ten newest ids
sequence = 1posts1 = 5
Truth to preserve / Cost target
Truth to preserve

feed candidates come only from the user or currently followed authors

Cost target

O(P log P) simple query, improvable with a heap merge

Store follow relationships and timestamped posts. A feed query gathers posts from the user and followed authors, then returns the ten newest by global sequence.

Your call · What should guide every step of this algorithm?

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead