Skip to content

Latest commit

 

History

History

1152-AnalyzeUserWebsiteVisitPattern

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Analyze User Website Visit Pattern

Problem can be found in here!

Solution: Hash Table

def mostVisitedPattern(username: List[str], timestamp: List[int], website: List[str]) -> List[str]:
    patterns = Counter()
    user_pattern = defaultdict(list)

    for user, _, site in sorted(zip(username, timestamp, website)):
        user_pattern[user].append(site)

    for user, sites in user_pattern.items():
        patterns.update(set(combinations(sites, 3)))

    return max(sorted(patterns), key=patterns.get)

Time Complexity: O(n!), Space Complexity: O(n)