Advertisement
Guest User

Directi Q1

a guest
Mar 28th, 2015
680
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. 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.
  2. 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.
  3. Print the value of max(n(A),n(B)) after all the operations.
  4. Sample Input
  5.  
  6. 3
  7. 7
  8. directi
  9. itcerid
  10. 5
  11. ababa
  12. babab
  13. 5
  14. abaaa
  15. baabb
  16.  
  17. Sample Output
  18.  
  19. 4
  20. 1
  21. 2
  22. Explanation
  23.  
  24. 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