Amazon Interview Question: Find the Most Frequent 3-Page Visit Pattern from Web Logs

19 Views
No Comments

Amazon has web server logs from multiple hosts.
Each log entry consists of:

  • a Session ID
  • a Web Page ID

Example (conceptual):

session_id, web_page_id
0001, product_1
0001, cart
0002, product_2
0003, home_page
0005, help
0001, checkout
0002, cart
0001, help
0001, product_1
0002, checkout
0005, checkout
0002, help

We want to find the 3-page pattern that is visited most frequently across all sessions.

In the example, the sequence <cart, checkout, help> appears twice, so it is the most frequent 3-page pattern.

Given logs in the form:

logs = [
  session:0001, web:product_1
  session:0001, web:cart
  session:0002, web:product_2
  session:0003, web:home_page
  session:0005, web:help
  session:0001, web:checkout
  session:0002, web:cart
  session:0001, web:help
  session:0001, web:product_1
  session:0002, web:checkout
  session:0005, web:checkout
  session:0002, web:help
]

Return the 3-page sequence that is most frequently visited, counting only in-order sequences within the same session.


Group logs by session ID, sort each session’s pages by time if needed, then within each session slide a window of size 3 to extract all 3-page sequences. Use a hash map to count frequencies, and return the sequence with the highest count.

The VOprep team has long accompanied candidates through various major company OAs and VOs, including Google, Amazon, Citadel, SIG, providing real-time voice assistance, remote practice, and interview pacing reminders to help you stay smooth during critical moments. If you are preparing for these companies, you can check out our customized support plans—from coding interviews to system design, we offer full guidance to help you succeed.

END
 0