Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- You are given two strings, say A and B, of the same length, say N. You can swap A[i] and B[i] for all i between 1 and N, inclusive. You cannot swap two characters within A, or within B. Also, you can only swap a character in A with the character at the same index in B, and with no other character. You can perform this operation zero or more times.
- You wish to modify the strings through the operations in such a way that the number of unique characters in the strings is small. In fact if n(A) is the number of unique characters in A and n(B) is the number of unique characters in B; you wish to perform the operations such that max(n(A),n(B)) is as small as possible.
- Print the value of max(n(A),n(B)) after all the operations.
- Sample Input
- 3
- 7
- directi
- itcerid
- 5
- ababa
- babab
- 5
- abaaa
- baabb
- Sample Output
- 4
- 1
- 2
- Explanation
- In the first test case, initially max(n(directi),n(itcerid)) = 6. You can modify the two strings such that they are "iirerii" and "dtcectd". String A has 3 unique characters and String B has 4 unique characters. Hence answer is 4. You cannot do better.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement