Skip to content

Instantly share code, notes, and snippets.

@thearyanag
Created September 9, 2022 14:05
Show Gist options
  • Select an option

  • Save thearyanag/c7dd01f5ec3df0199a0fd8be30c80eed to your computer and use it in GitHub Desktop.

Select an option

Save thearyanag/c7dd01f5ec3df0199a0fd8be30c80eed to your computer and use it in GitHub Desktop.
Given n email addresses of different domains, please send an email to the first address(in alphabetical order) of each domain.
// Given n email addresses of different domains, please send an email to the first address(in alphabetical order) of each domain.
// Please assume a function sendmail() to send the emails.A sample email array is following
// {ghi@hotmail.com, def@yahoo.com, ghi@gmail.com, abc@channelier.com, abc@hotmail.com, def@hotmail.com, abc@gmail.com,
// abc@yahoo.com, def@channelier.com,jkl@hotmail.com, ghi@yahoo.com, def@gmail.com }
import java.util.*;
void sendMail(String arr[])
{
Arrays.sort(arr);
List<String> emailList = new ArrayList<>();
Collections.addAll(emailList,arr);
for(int i=0 ; i<emailList.size() ; i++)
{
String hostMail = emailList.get(i);
String hostDomain = hostMail.substring(hostMail.indexOf('@'));
sendmail(hostMail);
for(int j=0 ; j<l ; j++)
{
String subMail = emailList.get(j);
String subDomain = subMail.substring(subMail.indexOf('@'));
if(subDomain.equalsToIgnoreCase(hostDomain))
emailList.remove(j);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment