Analyze User Website Visit Pattern
Medium · Hashing · about 30 minutes
Asked at Amazon, Spotify, Uber, Google, Twitch.
Three arrays of the same length describe browsing history: user username[i] opened website[i] at time timestamp[i], and no two timestamps are equal. A pattern is any sequence of three websites (repeats allowed). A user follows a pattern when those three sites appear, in that order, somewhere within their visits ordered by time (not necessarily back to back). A pattern's score counts how many distinct users follow it. Return the pattern with the top score, breaking ties by choosing the alphabetically smallest pattern.