Thursday, May 19, 2022
HomeSoftware DevelopmentRely distinctive domains from given Checklist of Emails

# Rely distinctive domains from given Checklist of Emails

Given an array arr[] containing N electronic mail addresses with completely different domains, the duty is to seek out the distinctive domains and their frequencies from the checklist of emails.

Notice:  The prevalence of the area should be printed within the lexicographical order of domains.

Examples:

Enter: arr[] = { “rupesh@gmail.com”, “akole@yahoo.com”, “rupesh.21910879@viit.ac.in”,
“college.surname@viit.ac.in”, “Shyam@gmail.com”, “examcell@viit.ac.in”}
Output: gmail.com 2
viit.ac.in 3
yahoo.com 1
Clarification:  Right here the distinctive domains in lexicographical order from the checklist of emails are:
gmail.com, viit.ac.in, yahoo.com.
And their respective frequecy within the checklist is 2, 3 and 1.

Output: geeksforgeeks.org 1
gmail.com 1

Strategy: The answer to the issue is predicated on the next thought:

The domains of an electronic mail are talked about after the ‘@’ image. So, discover all of the domains and retailer their frequencies.

Comply with the steps talked about beneath to implement the thought:

• Initialize a map to retailer the frequencies of every distinctive area within the lexicographical order of domains.
• Transverse every of the e-mail entries:
• For every entry discover the index (say idx) of the ‘@’ image.
• The substring ranging from idx+1 until the tip of the string is the area identify.
• Retailer this area within the map and improve its frequency by 1.
• Iterate the map from begin (as the important thing are already in sorted order) and print the domains and their frequencies.

Under is the implementation of the above method.

## C++

 ` `  `#embody ` `utilizing` `namespace` `std;` ` `  `vector > finddomains(` `    ``vector enter)` `{` `    ` `    ` `    ``map domainFre;` `    ``vector > ans;` ` `  `    ` `    ``for` `(``int` `i = 0; i < enter.measurement(); i++) {` ` `  `        ` `        ``auto` `findindex = enter[i].discover(``'@'``);` ` `  `        ` `        ` `        ` `        ``domainFre[input[i].substr(findindex + 1)]++;` `    ``}` ` `  `    ` `    ` `    ``for` `(``auto` `it : domainFre)` `        ``ans.push_back({ it.first, it.second });` ` `  `    ` `    ``return` `ans;` `}` ` `  `int` `fundamental()` `{` `    ``vector enter = {` `        ``"rupesh@gmail.com"``, ``"akole@yahoo.com"``,` `        ``"rupesh.21910879@viit.ac.in"``,` `        ``"college.surname@viit.ac.in"``,` `        ``"Shyam@gmail.com"``, ``"examcell@viit.ac.in"` `    ``};` `    ``vector > ans;` ` `  `    ` `    ``ans = finddomains(enter);` ` `  `    ` `    ` `    ` `    ``for` `(``int` `i = 0; i < ans.measurement(); i++)` `        ``cout << ans[i].first << ``" "` `             ``<< ans[i].second << endl;` `    ``return` `0;` `}`
Output

```gmail.com 2
viit.ac.in 3
yahoo.com 1```

Time Complexity: O(N * M) the place M is the typical string measurement
Auxiliary House: O(Okay) the place Okay is the variety of distinctive domains

RELATED ARTICLES