FastPrepMost Frequent Three-Page Sequences
Problems/Most Frequent Three-Page Sequences

Most Frequent Three-Page Sequences

Zillow logoZillow● MediumFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported at Zillow by two candidates in Seattle. A Software Developer candidate who interviewed in October 2015 took an online test, a technical phone call and then three technical onsite interviews, and accepted an offer. One onsite task was to go through click logs sorted by time and pick out the ten runs of three pages that come up most, where a run is three pages that one user visited back to back. A candidate for a Senior Software Development Engineer role in Rich Data, in August 2016, had a one-hour interview, coded in Java, on the most common three-page sequences. That report describes an interviewer who muted the call after giving the task, so we read the interview, the one the report describes, as a remote phone screen.

The 2015 report does not say how ties are ordered, and neither report gives the format of a log line. The 2015 wording could also be read as a separate top ten for every user; we read it as one list for the whole log, built from each user's own visits, which also fits the 2016 report.

These choices are ours: each log entry reaches the function as a pair of strings [user, page], already in time order; the count of sequences to return arrives as k (the 2015 report asked for ten); a sequence counts each time it appears, a page may repeat inside it, and users with fewer than 3 visits give none; ties go to the alphabetically smaller pages; the log has 1 to 5000 entries, names have 1 to 10 lowercase letters, and k is 1 to 10; the task can be solved in five languages instead of Java alone.

Our version is about 85% the same as the reported question.

A website keeps a log of page visits in the order they happened. Each entry logs[i] = [user, page] says that user opened page, and an entry with a smaller index happened earlier.

Read each user's own visits in log order. A three-page sequence is three pages that one user opened one right after another: three back-to-back entries in that user's own list of visits. Entries of other users in between do not break a sequence. A user with v visits gives v - 2 sequences, or none when v is less than 3. A sequence counts once every time it appears, even when the same user repeats it.

Return the k sequences that appear most often across all users, each written as [page1, page2, page3]. List them from most to fewest appearances. When two sequences appear the same number of times, the one whose first page comes first in alphabetical order goes first; if the first pages match, compare the second pages, then the third. If there are fewer than k different sequences, return all of them.

Function

topPageSequences(logs: List<List<String>>, k: int) → List<List<String>>

Examples

Example 1

logs = [["ann","home"],["bob","home"],["cat","search"],["ann","search"],["bob","search"],["ann","listing"],["cat","listing"],["bob","listing"],["ann","home"]]k = 1return = [["home","search","listing"]]

In log order, ann opens home, search, listing, home; bob opens home, search, listing; cat opens search, listing. ann gives two sequences, [home, search, listing] and [search, listing, home], and bob gives [home, search, listing]. cat has only 2 visits, so cat gives none. [home, search, listing] appears 2 times and [search, listing, home] 1 time, so with k = 1 the answer holds the first one.

Example 2

logs = [["dee","home"],["dee","map"],["dee","saved"],["dee","home"],["dee","map"],["dee","saved"]]k = 2return = [["home","map","saved"],["map","saved","home"]]

dee gives four sequences: [home, map, saved], [map, saved, home], [saved, home, map] and [home, map, saved] again, so the first one appears 2 times. The other two appear 1 time each. They tie, and map comes before saved in alphabetical order, so [map, saved, home] takes the second place.

Example 3

logs = [["eve","home"],["fay","search"],["eve","home"],["fay","home"],["eve","home"]]k = 10return = [["home","home","home"]]

eve opens home 3 times, which gives the one sequence [home, home, home]; a page may repeat inside a sequence. fay has only 2 visits. There is 1 sequence in total, fewer than k = 10, so the answer holds just that one.

Constraints

  • 1 <= logs.length <= 5000
  • logs[i].length == 2
  • Each user and each page has 1 to 10 lowercase English letters.
  • 1 <= k <= 10

More Zillow Phone Screen questions

  • Valid ParenthesesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2025
  • Time Based Key-Value StorePHONE SCREEN · Seen Feb 2024
  • Filter Formatted Records by CriteriaPHONE SCREEN · Seen Sep 2023
  • Build a Hash TablePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2023
  • Jump GamePHONE SCREEN · Seen Dec 2022
  • Reversible Run-Length EncodingPHONE SCREEN · Seen Nov 2022
  • Spiral MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2022
  • Two Sum: All PairsPHONE SCREEN · Seen Nov 2022
  • Employee Free TimePHONE SCREEN · Seen Oct 2022
  • First Unique Character in a StringPHONE SCREEN · Seen Oct 2022

Similar questions at other companies

  • Group AnagramsAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
  • Longest Consecutive Login StreakAmazon · ONSITE INTERVIEW
  • Group AnagramsWorkday · PHONE SCREEN
  • Group AnagramsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Group AnagramsEPAM · PHONE SCREENEPAM interview questions
  • Find Duplicate Element PairsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Find Duplicate File GroupsAnthropic · PHONE SCREENAnthropic interview questions
  • Insert an Employee into an Organization HierarchyWaymo · PHONE SCREENWaymo interview questions
  • Deep Merge with a Conflict ResolverAutodesk · ONSITE INTERVIEWAutodesk interview questions
  • Group Duplicate Files by ContentPostman · ONSITE INTERVIEWPostman interview questions
All Zillow interview questionsSee Zillow hiring insights
Saved
class Solution {
    public List<List<String>> topPageSequences(List<List<String>> logs, int k) {
        // Write your code here.
    }
}
Checking account…