Find the Most Common Three-Page Navigation Paths on Amazon.com

Last updated: November 29, 2026

Quick Overview

Given page view logs with session IDs, return the top three-page navigation paths by the number of sessions containing them, collapsing consecutive refreshes of the same page.

Amazon
Data Manipulation (SQL/Python)
Software Engineer
Amazon
November 29, 2026
Software Engineer
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Given page view logs with session IDs, return the top three-page navigation paths by the number of sessions containing them, collapsing consecutive refreshes of the same page.

A Python path analysis question in the style of Amazon retail website teams, who look at common navigation sequences to find dead ends and detours between search, detail page and cart. The interviewer checks per-session ordering, a clear counting rule, and a deterministic ranking.

What the Interviewer Expects
  • Group views by session and sort by timestamp
  • Collapse consecutive duplicate pages caused by refreshes
  • Generate contiguous n-grams of pages
  • Count each distinct path once per session, and justify it
  • Break ties deterministically and handle short sessions
Key Topics to Cover
path analysis
n-grams
Counter
sessions
Python
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you count paths by total occurrences instead and when would you prefer that?
  • How would you find the most common path that ends in a purchase?
  • How would you run this on billions of page views with Spark?
  • How would you surface paths that lead to session exits?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

Input: a list of (session_id, ts, page) tuples, where page is a page type such as home, search, detail, cart. Rules to confirm: consecutive repeats of the same page (refresh or back to sam...

Approach

For each session: sort, collapse adjacent duplicates, then slide a window of length three to make tuples. A set per session gives the once-per-session rule. A Counter aggregates across sessions. Sor...


Submit Your Answer
Markdown supported