Analyze User Website Visit Pattern

Medium

Company Tags

You are given two string arrays username and website and an integer array timestamp. All the given arrays are of the same length and the tuple (username[i], website[i], timestamp[i]) indicates that the user username[i] visited the website website[i] at time timestamp[i].

A list of three websites is called a pattern (not neccessarily distinct).

  • For example, ["neetcode", "courses", "problems"], ["neetcode", "love", "neetcode"], and ["dsa", "dsa", "dsa] are all patterns.

The score of a pattern is the number of users visited all the websites in the pattern in the same order they appeared in the pattern. In other words, for a given users' sequence of website visits, the pattern must appear as a subsequence within that sequence.

Your task is to return the pattern with the largest score. If there is more than one pattern with the same largest score, return the lexicographically smallest such pattern.

Example 1:

Input: username = ["bob","bob","bob","alice","alice","alice","alice","charlie","charlie","charlie"], timestamp = [1,2,3,4,5,6,7,8,9,10], website = ["home","about","career","home","cart","maps","home","home","about","career"]

Output: ["home","about","career"]

Example 2:

Input: username = ["ua","ua","ua","ub","ub","ub"], timestamp = [1,2,3,4,5,6], website = ["a","b","a","a","b","c"]

Output: ["a","b","a"]

Constraints:

  • 1 <= username.length == timestamp.length == website.length <= 50
  • 1 <= username[i].length <= 10
  • 1 <= timestamp[i] <= 1,000,000,000
  • 1 <= website[i].length <= 10
  • username[i] and website[i] is made up of lowercase English letters.
  • It is guaranteed that there is at least one user who visited at least three websites.
  • All the tuples (username[i], timestamp[i], website[i]) are unique.


Company Tags

Please upgrade to NeetCode Pro to view company tags.

username =

timestamp =

website =