← 返回 amazon 的题目列表Find Top K Visited Domains
类型:online_judge
amazon
Given a list of sub-domains sub_domains and a list of domains domains, find the top K most visited domains and their visit counts. Solve the problem using a prefix tree.
Input:
sub_domains: A list of strings, each representing a sub-domain.
domains: A list of strings, each representing a domain.
k: An integer, indicating the number of top most visited domains to find.
Output: Return a list with each entry containing the domain and its visit count.
Example:
sub_domains = ["news.apple.cn", "news.apple.com", "ipod.apple.com", "hello.hi.apple.com", "finance.yahoo.com","tea.yahoo.com", "finance.yahooooo.com", "hello.google.com", "news.google.com", "ai.google.com"]
domains = ["apple.com", "yahoo.com", "google.com"]
k = 2
Output Example:
[("apple.com", 3), ("google.com", 3)]
Example
Input
news.apple.cn
news.apple.com
ipod.apple.com
hello.hi.apple.com
finance.yahoo.com
tea.yahoo.com
finance.yahooooo.com
hello.google.com
news.google.com
ai.google.com
apple.com
yahoo.com
google.com
2