User Journey Paths from a Log Stream
Updated
Problem statement
A platform records what its users do, but the logs now arrive one at a time while the platform keeps running. You are given the array events in arrival order. Each event is either a log "user_id time action" or the word "SUMMARY".
For every SUMMARY, produce the journey tree of all logs that arrived before it, as an array of text lines. Return one array of lines per SUMMARY, in order.
The journey tree works like this:
- A user's journey is that user's actions sorted by
time, smallest first. Logs arrive in time order, so this is also the order in which the user's logs arrive. - Each journey is put into one tree. Each node is one action, and a path from the top of the tree is a start of a journey. A repeated action is a new step: in
A -> B -> Bthe secondBis a child of the firstB. - Each node has a
count: the number of different users whose journey so far follows that exact path down to the node.
Each summary lists the tree, without its top, as lines:
- Each line is
ACTION (count). - The first actions of the journeys are at depth
0and have no prefix. A node at depthd(1 or more) starts with2*dspaces and then->. So depth 1 starts with->(two spaces) and depth 2 with->(four spaces). - Print a node's line first, then everything below it, before the next sibling. Siblings go in plain character order of the action, so
Acomes beforeB, andBcomes beforea. - A summary before any log is an empty array.
Function
journeySummaries(events: String[]) → List<List<String>>Examples
Example 1
events = ["1 10 A","2 12 A","SUMMARY","1 15 B","SUMMARY"]return = [["A (2)"],["A (2)"," -> B (1)"]]At the first SUMMARY, users 1 and 2 have each done A, so the tree is the single line A (2). Then user 1 does B. At the second SUMMARY, B hangs under A with a count of 1.
Example 2
events = ["SUMMARY","5 1 home","SUMMARY"]return = [[],["home (1)"]]The first SUMMARY comes before any log, so its tree is empty. After user 5 does home, the tree has one line.
Example 3
events = ["1 1 A","1 2 A","2 3 b","2 4 B","SUMMARY"]return = [["A (1)"," -> A (1)","b (1)"," -> B (1)"]]User 1 does A twice, so the second A is a child of the first. User 2 does b then B. At the top level A comes before b, because uppercase letters come before lowercase ones in character order.
Example 4
events = ["1 5 A","2 5 A","1 6 B","2 7 C","1 8 C","SUMMARY","2 9 B","SUMMARY"]return = [["A (2)"," -> B (1)"," -> C (1)"," -> C (1)"],["A (2)"," -> B (1)"," -> C (1)"," -> C (1)"," -> B (1)"]]Users 1 and 2 both start with A at time 5. Before the first SUMMARY, user 1 has gone A, B, C and user 2 has gone A, C. After it, user 2 does B, which goes under that user's C, not at the top. Each new log continues the journey of its own user.
Constraints
1 <= events.length <= 10^4- Each event is
"SUMMARY"or a log of three fields separated by single spaces: an integeruser_id, an integertime, and anaction. At least one event is"SUMMARY". user_idandtimeare between0and10^9, written without leading zeros.- Each
actionhas1to10letters or digits. - Logs arrive in time order: each log's
timeis at least thetimeof the log before it. Two logs of the same user never have the sametime. - Each user has at most
50logs. - All summaries together have at most
2 * 10^4lines.
More WhatNot Phone Screen questions
- Adjacent Pair and Run RemovalPHONE SCREEN · Seen Nov 2026
- Merge Sorted Squares of Two ArraysPHONE SCREEN · Seen Nov 2026
- User Journey PathsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Knight Dialer SequencesPHONE SCREEN · Seen Oct 2026
- Reachable Exits in an Obstacle GridPHONE SCREEN · Seen Oct 2026
- Palindrome with One DeletionPHONE SCREEN · Seen Oct 2026
- Search a 2D MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Attraction Route Without Reusing TrailsPHONE SCREEN · Seen Sep 2026
- Earliest Car for Each PassengerPHONE SCREEN · Seen Sep 2026
- Minimum Stores for a Shopping ListPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Domain Weight CalculationAmazon · ONSITE INTERVIEW
- N-ary Index-Path Encoder and DecoderBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Task Build Order and File-Change RerunsVanta · PHONE SCREEN
- Account Roles With Parent-User InheritanceStripe · PHONE SCREENStripe interview questions
- Resolve Variable Equations with Dependency ErrorsApplied Intuition · PHONE SCREENApplied Intuition interview questions
- Nested Substitutions with Cycle DetectionKikoff · PHONE SCREENKikoff interview questions
- Validate a BST with a Custom ComparisonApple · PHONE SCREENApple interview questions
- Validate and Resolve Evaluation ChainsPlaid · PHONE SCREEN · ONSITE INTERVIEWPlaid interview questions
- Route Graph Reachability with a Broken LinkFigma · PHONE SCREENFigma interview questions
- Root of the Largest TreeGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions