Summarize User Journeys with an Incrementally Updated Trie

Quick Overview

Build user-journey summaries with trie prefix counts, sorted batch logs, and constant-time ordered-stream updates using one current node per user.

Summarize User Journeys with an Incrementally Updated Trie

Company: Whatnot

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Given unsorted logs `(userId, timestamp, action)`, group each user's logs in timestamp order and build a trie of their action sequences. Each node stores the number of users whose journey passes through that prefix. Print the trie in preorder with indentation and counts. Repeated occurrences of one action are distinct steps. Then support streaming logs without rebuilding the trie: each user's events arrive in order, but events from different users interleave. Ingest each event and allow a summary at any time. ### Constraints & Assumptions For equal timestamps in batch input, preserve input order as an explicit practice tie-breaker. For deterministic rendering, visit child actions lexicographically and output `(depth, action, count)` rows; indentation is a presentation of depth. Exclude the synthetic root from output. ### Clarifying Questions to Ask - How are a user's simultaneous events ordered? - Do counts mean users passing through a prefix rather than total occurrences of an action anywhere? - Is per-user event order guaranteed for the streaming follow-up? ### Part 1 — Batch summaries Build the per-user sequences, insert each once, and output preorder counts. #### What This Part Should Cover - Per-user timestamp sorting and distinct repeated-action positions. - Counts on shared prefix nodes and deterministic traversal. ### Part 2 — Streaming updates Maintain the trie and update it for each arriving event without rebuilding previous paths. #### What This Part Should Cover - One current trie-node pointer per user. - One child transition and count increment per new event. - The distinction between ingestion cost and full-summary output cost. ```hint Remember each user's frontier An ordered new event extends that user's current journey by exactly one edge. ``` ### What a Strong Answer Covers - Equivalent batch and stream semantics under matching per-user order. - Correct user counts and memory proportional to stored prefixes and users. ### Follow-up Questions - Why would out-of-order events invalidate the simple per-user pointer update? - What buffering or watermark policy could support bounded lateness?

Overview: Build user-journey summaries with trie prefix counts, sorted batch logs, and constant-time ordered-stream updates using one current node per user.

Read the full Whatnot Software Engineer interview experience this question came from

Whatnot logo
Whatnot
Nov 6, 2026
mediumSoftware EngineerTechnical ScreenCoding & Algorithms
3
0

Given unsorted logs (userId, timestamp, action), group each user's logs in timestamp order and build a trie of their action sequences. Each node stores the number of users whose journey passes through that prefix. Print the trie in preorder with indentation and counts. Repeated occurrences of one action are distinct steps.

Then support streaming logs without rebuilding the trie: each user's events arrive in order, but events from different users interleave. Ingest each event and allow a summary at any time.

Constraints & Assumptions

For equal timestamps in batch input, preserve input order as an explicit practice tie-breaker. For deterministic rendering, visit child actions lexicographically and output (depth, action, count) rows; indentation is a presentation of depth. Exclude the synthetic root from output.

Clarifying Questions to Ask Guidance

  • How are a user's simultaneous events ordered?
  • Do counts mean users passing through a prefix rather than total occurrences of an action anywhere?
  • Is per-user event order guaranteed for the streaming follow-up?

Part 1 — Batch summaries

Build the per-user sequences, insert each once, and output preorder counts.

What This Part Should Cover Guidance

  • Per-user timestamp sorting and distinct repeated-action positions.
  • Counts on shared prefix nodes and deterministic traversal.

Part 2 — Streaming updates

Maintain the trie and update it for each arriving event without rebuilding previous paths.

What This Part Should Cover Guidance

  • One current trie-node pointer per user.
  • One child transition and count increment per new event.
  • The distinction between ingestion cost and full-summary output cost.

What a Strong Answer Covers Guidance

  • Equivalent batch and stream semantics under matching per-user order.
  • Correct user counts and memory proportional to stored prefixes and users.

Follow-up Questions Guidance

  • Why would out-of-order events invalidate the simple per-user pointer update?
  • What buffering or watermark policy could support bounded lateness?