#P8040. Lexicographically Smallest Non-Matching Word
Lexicographically Smallest Non-Matching Word
Lexicographically Smallest Non-Matching Word
Given an integer (N), Slavko writes down (N) letters (each from the set ({a, b, c})). Then Mirko writes a word of length (N). Slavko must rearrange his letters to form a new word such that for every index (i) (0-indexed), the letter in the new word is different from the letter in Mirko's word at the same position. Among all possible valid words, Slavko must choose the lexicographically smallest one. It is guaranteed that such a word exists.
Note: The lexicographical order is defined by the natural order of characters: (a < b < c).
inputFormat
The first line contains an integer (N).
The second line contains a string of length (N) representing the letters Slavko wrote down.
The third line contains a string of length (N) representing Mirko's word.
outputFormat
Output the lexicographically smallest valid word that can be formed by rearranging Slavko's letters such that the letter at each position is different from Mirko's letter at that position.
sample
3
abc
abc
cab