I didn't said Factory, or Decorator or Facade because I am terrible with terminology. i applied those patterns in the past but I don't know them by the name. they were looking for someone that can code out of their head. Like google does, only that google pays 40% more so if you are this type of guy don't waste your time on Avaloq.
iterate over the first string and hash the characters with triple values (char,found). You need not to hash the same characters twice !! when you iterate the second string check the characters in the Hash and if you find it mark found = true, print the character, if already found continue. linear space and time.