Longest Browsing Session Without Revisiting the Same Product Page

Last updated: November 29, 2026

Quick Overview

Given the sequence of product IDs a shopper viewed, return the length of the longest contiguous stretch in which no product ID repeats.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given the sequence of product IDs a shopper viewed, return the length of the longest contiguous stretch in which no product ID repeats.

An Amazon technical screen question built on clickstream data from product detail pages. The interviewer looks for a sliding window with a last-seen index map that jumps the left pointer, and for correct handling of stale indices that are already outside the window.

What the Interviewer Expects
  • Maintain a window of distinct IDs with two pointers
  • Store the last index of each ID in a hash map
  • Jump the left pointer past the previous occurrence
  • Never move the left pointer backward on a stale index
  • State O(n) time and O(min(n, distinct)) space
Key Topics to Cover
Sliding Window
Hash Map
Two Pointers
Clickstream
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Return the session itself, not only its length.
  • What if a repeat is allowed when visits are more than 10 minutes apart?
  • How would you compute this per user over a streaming clickstream?
Sharpen Your Skills on Codemia

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

Practice DSA Problems
Sample Answer
Requirements

Input: list views of hashable product IDs. Output: maximum length of a contiguous subarray with all distinct IDs. Empty input gives 0....

High-Level Design

Keep a window [left, right] with no repeats and a dictionary last of each ID's latest index. When views[right] was last seen at index p >= left, the window must start after p, so set `left =...


Submit Your Answer
Markdown supported