## 1. Unique Email Addresses

**The Problem**

Start by reading the description of the problem,

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 "alice@leetcode.com", "alice" is the local name, and "leetcode.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, "alice.z@leetcode.com" and "alicez@leetcode.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, "m.y+name@email.com" will be forwarded to "my@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 emails[i], return the number of different addresses that actually receive mails.

The description might look big and scary but believe me question is

not that scary when it comes to the implementation, basically the question is saying

An email is divide into two parts the part before @ is called local name, the part after @ is called domain name.

In the question we have to handle following cases:

Dots (.) in the local name can be ignored.

Everything after the first plus sign (+) in the local name is discarded.

The domain name is not altered by dots or plus signs. It is used as is.

3.Two email addresses are considered the same if, after applying the above rules, they are identical.

4.You need to count how many unique addresses there are after applying these rules.

Looks easy isn't it.

Refer the example for better understanding,

**Approach**

Our approach for this question is going to be pretty straightforward,

- Find @ symbol divide the email in local name and domain name.
- Find '+' and '.' sign in local name and process it.
- Merge the local and domain name together and give the answer.

**Solution**

We have achieved this solution by following ways,

Declare an unordered set unique to store the final answer.

Traverse the string and find the @ symbol.

When you find @ divide the part before @ as local name and part after that as domain name.

Declare a variable processedLocal as string datatype.

Traverse LocalName, if you find '+' symbol break because we have to ignore the values after + and if you find '.' symbol ignore it and add the rest of string in processedLocal variable.

Declare a string final where we give merged email of processedLocal, @ and domain Name.

Insert the final into the set unique.

Return the size of unique.

## 2. Remove Element

**The Problem**

Start by reading the description of problem

Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The order of the elements may be changed. Then return the number of elements in nums which are not equal to val.

Consider the number of elements in nums which are not equal to val be k, to get accepted, you need to do the following things:

Change the array nums such that the first k elements of nums contain the elements which are not equal to val. The remaining elements of nums are not important as well as the size of nums.

Return k.

Question is pretty straight forward and easy we just have to remove a given element from an array and return the size of the array after removing it, the only catch is that the positions will change.

Refer the examples for better understanding,

**Approach**

The approach to solve this question is short and pretty straight forward,

- Iterate the array
- Check and move valid elements

**Solution**

Steps to achieve this solution is as follows,

Initialise the variable index with 0 to keep track of position where next valid element should be placed.

Iterate through the vector.

Check if current element equal to value if not move it to position indicated by index and then increment the index to update next position.

Return index.

## 3.Group Anagrams

**The Problem**

Start by reading the description

Given an array of strings strs, group the anagrams together. You can return the answer in any order.

Well, I this time I guess question is understandable by description only.

Refer to example for better understanding.

**Approach**

- Use hashmap to map each sorted string.
- Sort the string.
- Group by sorted string.
- Add groups to result.
- Return result.

**Solution**

Initialise a result vector this will store final grouped anagram.

Initialise a hash map to map sorted string to a vector of original strings that are anagrams of that key.

Loop through each string in input vector.

Sort the strings as it helps in identifying anagrams.

Add original string to vector associated with its sorted version in hashmap. This groups all anagrams together under same key.

Iterate through hashmap and add each group of anagrams to result vector.

Return result.

I hope the solutions I have provided are understandable and explanations are easy to understand.

Thank You

You can connect with me on Linkedin

## Top comments (0)