Enrollments closing soon for Post Graduate Certificate Program in Applied Data Science & AI By IIT Roorkee | 3 Seats Left

  Apply Now

Data Structures and Algorithms Questions

4 / 13

Unique Email Addresses

Every valid email consists of a local name and a domain name, separated by the '@' sign. Besides lowercase letters, the email may contain one or more '.' or '+'.

  • For example, in "reachus@cloudxlab.com", "reachus" is the local name, and "cloudxlab.com" is the domain name.

If you add periods '.' between some characters in the local name part of an email address, mail sent there will be forwarded to the same address without dots in the local name. Note that this rule does not apply to domain names.

  • For example, "jon.ny@cloudxlab.com" and "jonny@cloudxlab.com" forward to the same email address.

If you add a plus '+' in the local name, everything after the first plus sign will be ignored. This allows certain emails to be filtered. Note that this rule does not apply to domain names.

  • For example, "co.ol.+name@email.com" will be forwarded to "cool@email.com". It is possible to use both of these rules at the same time.

Given an array of strings emails where we send one email to each email[i], return the number of different addresses that actually receive mails.

Input: emails = ["main.email+check@cloudxlab.com","main.e.mail+bobby.caty@cloudxlab.com","mai.n.e.m.ail+monalisa@cloud.x.lab.com"]   
Output: 2
Explanation: "mainemail@cloudxlab.com" and "mainemail@cloud.x.lab.com" actually receive mails.

Input: emails = ["aazz@cloudxlab.com","b@cloudxlab.com","c@cloudxlab.com"]
Output: 3

Constraints:

  • 1 <= len(emails)<= 100
  • 1 <= len(emails[i])<= 100
  • email[i] consist of lowercase English letters, '+', '.' and '@'.
  • Each emails[i] contains exactly one '@' character.
  • All local and domain names are non-empty.
  • Local names do not start with a '+' character.
INSTRUCTIONS

  1. Write your code inside a function named unique_emails
  2. There are no partial marks for the question.
  3. Your function must return the output, it should not print the output.
  4. To execute a block on the right-side coding panel, please press 'shift'+ 'enter' inside the block.
  5. Your code should work for all permitted possible values(check Constraints) of emails

Complete the below code in the right side coding panel

def unique_emails(prices: list) -> int:
    # your code goes here
See Answer

No hints are availble for this assesment


Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...