[Swift] LeetCode1152 website user access behavior analysis |. Analyze User Website Visit Pattern

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤ micro-channel public number: to dare (WeiGanTechnologies)
➤ blog Park address: San-ching Wing Chi ( https://www.cnblogs.com/strengthen/ )
➤GitHub address: https://github.com/strengthen/LeetCode
➤ original address: HTTPS: //www.cnblogs. com / strengthen / p / 11333856.html 
➤ If the address is not a link blog Park Yong Shan Chi, it may be crawling author of the article.
➤ text has been modified update! Click strongly recommended that the original address read! Support authors! Support the original!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

You are given three arrays usernametimestamp and website of the same length N where the ithtuple means that the user with name username[i] visited the website website[i] at time timestamp[i].

3-sequence is a list of not necessarily different websites of length 3 sorted in ascending order by the time of their visits.

Find the 3-sequence visited at least once by the largest number of users. If there is more than one solution, return the lexicographically minimum solution.

A 3-sequence X is lexicographically smaller than a 3-sequence Y if X[0] < Y[0] or X[0] == Y[0] and (X[1] < Y[1] or X[1] == Y[1] and X[2] < Y[2])

It is guaranteed that there is at least one user who visited at least 3 websites. No user visits two websites at the same time.

Example 1:

Input: username = ["joe","joe","joe","james","james","james","james","mary","mary","mary"], 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"]
Explanation: 
The tuples in this example are:
["joe", 1, "home"]
["joe", 2, "about"]
["joe", 3, "career"]
["james", 4, "home"]
["james", 5, "cart"]
["james", 6, "maps"]
["james", 7, "home"]
["mary", 8, "home"]
["mary", 9, "about"]
["mary", 10, "career"]
The 3-sequence ("home", "about", "career") was visited at least once by 2 users.
The 3-sequence ("home", "cart", "maps") was visited at least once by 1 user.
The 3-sequence ("home", "cart", "home") was visited at least once by 1 user.
The 3-sequence ("home", "maps", "home") was visited at least once by 1 user.
The 3-sequence ("cart", "maps", "home") was visited at least once by 1 user.

Note:

  1. 3 <= N = username.length = timestamp.length = website.length <= 50
  2. 1 <= username[i].length <= 10
  3. 0 <= timestamp[i] <= 10^9
  4. 1 <= website[i].length <= 10
  5. Both username[i] and website[i] contain only lowercase characters.

In order to assess a site's conversion rates, we need to analyze the access behavior of the user, and the establishment of user behavior model. Log files have been recorded user name, access times and page path.

For analytical purposes, the log file  N records have been resolved to the same length and a length three are  N arrays, are: a user name  username, access time  timestamp , and a page path  website. The first  i record means that the user name  username[i] of the user  timestamp[i] when visiting the path  website[i] of the page.

We need to find when users visit the site "were sexually path", which is the largest number of users visited at least once by a certain order of three pages path. Note that the user may not be continuous access to the three paths.

"Total sexual path" is a path length of page 3 of the list, the list is not necessarily a different path, and arranged in ascending order has access time.

If there are multiple answers to meet the requirements, then please return the smallest of the arrangement according to the dictionary order. (Page path list  X lexicographical ordering less than  Y a prerequisite: X[0] < Y[0] or  X[0] == Y[0] 且 (X[1] < Y[1] 或 X[1] == Y[1] 且 X[2] < Y[2]))

Topic ensure that a user can access the same path at least three pages, and a user does not access two different paths pages at the same time.

Example:

输入:username = ["joe","joe","joe","james","james","james","james","mary","mary","mary"], timestamp = [1,2,3,4,5,6,7,8,9,10], website = ["home","about","career","home","cart","maps","home","home","about","career"]
输出:["home","about","career"]
解释:
由示例输入得到的记录如下:
["joe", 1, "home"]
["joe", 2, "about"]
["joe", 3, "career"]
["james", 4, "home"]
["james", 5, "cart"]
["james", 6, "maps"]
["James ",. 7," Home "] 
there are a user visited at least once ( "home", " cart "," home ").
there are a user visited at least once ( "home", "cart"
There are two users visited at least once ( "home", "about"
[" Mary ", 10," Career "]
[" Mary ",. 9," About "]
[" Mary ",. 8," Home "]"cart", "home")。
There is a user visited at least once ( "home", "maps" , "home"). 
There is a user visited at least once ( "cart", "maps" , "home").

prompt:

  1. 3 <= N = username.length = timestamp.length = website.length <= 50
  2. 1 <= username[i].length <= 10
  3. 0 <= timestamp[i] <= 10^9
  4. 1 <= website[i].length <= 10
  5. username[i] And  website[i] only contain lowercase characters

Guess you like

Origin www.cnblogs.com/strengthen/p/11333856.html