bugger.
All challenges/JavaScripthardmeta-reaction-ordering-v1
THE INVESTIGATION

The removed reaction that returns

A delayed reaction event brings back a reaction the user already removed.

Meta-styleInterview practiceEvent ordering

What’s going wrong

Original Meta-style interview practice. This is not an actual Meta interview question. Bugger does not provide an AI assistant.

Reaction updates arrive more than once and out of order. The reducer ignores old events while a reaction is visible, yet a delayed “like” can reappear after the user removes it. Find the state that disappears during removal.

Input is {"events":[{"post":"p","user":"u","version":1,"reaction":"like"},...]}. The identity of a reaction is the pair (post, user). Version is a monotonically assigned sequence number for that pair, not the event’s delivery order. Apply an event only when its version is strictly greater than every previously seen version for the pair. A null reaction removes the visible reaction but is still a versioned update. A newer non-null event may add a reaction again.

Print an array of active {"post":...,"user":...,"reaction":...} objects sorted by post and then user in ASCII string order. Input has at most 200 events. Post and user are nonempty ASCII strings of at most 64 characters, including punctuation. Version is an integer from 0 to 1000000000. Reaction is null or a nonempty ASCII string. Duplicate events for the same pair/version always carry the same reaction. Repair applyEvent so stale deliveries cannot undo newer removals; keep each pair independent.

Expected behavior

Retain the highest seen version for each post/user pair, including removals; expose only non-null reactions and permit strictly newer additions.

Reproduction

01 Delayed like follows a newer removal
{"events":[{"post":"p","user":"u","version":1,"reaction":"like"},{"post":"p","user":"u","version":3,"reaction":null},{"post":"p","user":"u","version":2,"reaction":"love"}]}
[]
02 Out-of-order visible updates keep the newest
{"events":[{"post":"p","user":"u","version":4,"reaction":"love"},{"post":"p","user":"u","version":2,"reaction":"like"}]}
[{"post":"p","user":"u","reaction":"love"}]
03 A genuinely newer reaction restores visibility
{"events":[{"post":"p","user":"u","version":2,"reaction":null},{"post":"p","user":"u","version":3,"reaction":"wow"}]}
[{"post":"p","user":"u","reaction":"wow"}]

Before you begin

  • Maps and composite keys
  • Versioned events
  • Deletion markers

Need a nudge?

Reveal one investigation hint at a time. Try each clue before opening the next.

    The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.