Mission: Impossible – Dead Reckoning
Ethan Hunt and the IMF team must track down a terrifying new weapon that threatens all of humanity if it falls into the wrong hands. With control of the future and the fate of the world at stake, a deadly race around the globe begins.
He and his team must generate secret words to encrypt the details of a misson to locate a terrifying new weapon that poses a threat to all of humanity. The secret words will be used to unlock critical information about the weapon’s locations. These secret words are generated using two words str1 and str2.
To generate the secret word, follow the rules as below:
- Match each character in two strings, str1 and str2, one by one. (e=l,t=i,h=s …)
- Similar characters will be grouped together based on the equivalence relation: reflexivity, symmetry, and transitivity.
- For each character in the word containing classified data D, find the first most letter alphabetically in each similar character set from str1 and str2.
- If a character in D is not present in str1 or str2, it remains unchanged in the secret word.
Your task is to create program that takes three inputs: str1, str2, and D, and returns the secret word to complete the mission.
Example:
- str1=ethanhunt
- str2=lisafaust
- l=operationsecret
- Similar character sets : {e,l},{i,t},{a,f,h,s,n}
- Secret word : operaiioaaecrei
Input Format
First two lines contain str1 and str2.
Next line contains D.
Output Format
- Print the secret word in the console.
Constraints
- All the strings contain lowercase letters.
- str1.length==str2.length
- 1<= str1.length,str2.length,D.length <=1000
Sample Input 0
ethanhunt
lisafaust
operationsecret
Sample Output 0
operaiioaaecrei
Sample Input 1
underwater
parachutes
gabriel
Sample Output 1
gabcial
Open on HackerRank ↗ · Markdown source · Back to the archive