Subdomain visit count
livecode
Task condition
The website name, for example "discuss.leetcode.com", consists of multiple levels of domains. The top level is "com", the next is "leetcode.com", and the lowest is "discuss.leetcode.com". When accessing the full domain, such as "discuss.leetcode.com", it is automatically considered that its parent domains "leetcode.com" and "com" were also visited.
The visit count record has one of two formats: "cnt d1.d2.d3" or "cnt d1.d2", where cnt is the number of visits, and d1.d2.d3 is the domain name itself.
For example, the string "9001 discuss.leetcode.com" means that the domain discuss.leetcode.com was visited 9001 times.
Given an array of strings domainsList, each containing a visit count record. You need to return an array of strings, where each string reflects the total number of visits for each subdomain encountered in the input data. The order of strings in the response does not matter.
Example 1: Input: domainsList = ["9001 discuss.leetcode.com"] Output: ["9001 leetcode.com","9001 discuss.leetcode.com","9001 com"] Explanation: There is only one domain "discuss.leetcode.com" in the input. As described above, its subdomains "leetcode.com" and "com" are also considered visited, so each of them gets the same count of 9001.
Example 2: Input: domainsList = ["900 google.mail.com", "50 yahoo.com", "1 intel.mail.com", "5 wiki.org"] Output: ["901 mail.com","50 yahoo.com","900 google.mail.com","5 wiki.org","5 org","1 intel.mail.com","951 com"] Explanation: We visit "google.mail.com" 900 times, "yahoo.com" 50 times, "intel.mail.com" once, and "wiki.org" 5 times. For subdomains, we get: "mail.com" — 900 + 1 = 901, "com" — 900 + 50 + 1 = 951, "org" — 5.