How it Works ?
The Algorithm behind it!
- Write your and your friend's name and strike out the similar alphabets. For Eg:"Jack" , "Jane".
- Store the count of similar alphabets sequentially. For Eg: alphabets:['J','J','a','a'], Sequence:[2,2]
- Count the unique alphabets and store them in the same sequence as before. For Eg:alphabets:['c','k','n','e'], Sequence:[2,2,1,1,1,1]
- Now add the first and last values from the sequence and store it. For Eg: 2+1 = 3
- Now do the same for the 2nd character from the beginning and from the end in reverse. For Eg: 3 + ( 2 + 1).
- Continue doing the same process until the sequence reaches its end. If the sequence length is odd, add the final value.
- Now calculate the total count of the similar characters that we struck out earlier. For Eg:['J','a'] = 2
- Multiply that count with the answer we calculated earlier by adding the sequence values.
Try it out