Imagine you're a data analyst at a major tech company, tasked with understanding user behavior patterns on your platform. You have access to user browsing logs and need to identify the most popular 3-website sequences that users follow.
Given three arrays of equal length:
username- Array of usernameswebsite- Array of websites visitedtimestamp- Array of visit timestamps
Each triplet [username[i], website[i], timestamp[i]] represents a single visit event.
Your task is to find the most popular 3-website pattern - a sequence of exactly 3 websites that users visit in chronological order (not necessarily consecutively). The pattern's score is the number of unique users who visited all 3 websites in that exact order.
Goal: Return the pattern with the highest score. If there's a tie, return the lexicographically smallest pattern.
Example: If pattern ["home", "about", "career"] has score 5, it means 5 different users visited "home", then later "about", then later "career" (with possible other visits in between).
Input & Output
Visualization
Time & Space Complexity
N log N for sorting visits, then N users × V³ combinations per user
N×V for storing grouped visits, P for pattern frequency map
Constraints
- 3 ≤ username.length ≤ 50
- 1 ≤ username[i].length ≤ 10
- timestamp.length == username.length
- 1 ≤ timestamp[i] ≤ 109
- website.length == username.length
- 1 ≤ website[i].length ≤ 10
- username[i] and website[i] consist of lowercase English letters
- It is guaranteed that there is at least one user who visited at least 3 websites
- All the tuples [username[i], timestamp[i], website[i]] are unique