Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. Two strings, a and b, are said to be twins only if they can be made equivalent by performing some number of operations on one or both strings. There are two possible operations:
  2.  
  3. SwapEven: Swap a character at an even-numbered index with a character at another even-numbered index.
  4. SwapOdd: Swap a character at an odd-numbered index with a character at another odd-numbered index.
  5.  
  6. For example, a = "abcd" and b = "cdab" are twins because we can make them equivalent by performing operations. Alternatively, a = "abcd" and b = "bcda" are not twins (operations do not move characters between odd and even indices), and neither are a = "abc" and b = "ab" (no amount of operations will insert a 'c' into string b).
  7.  
  8. Complete the twins function in the editor below. It has two parameters:
  9.  
  10. An array of n strings named a.
  11. An array of n strings named b.
  12.  
  13. The function must return an array of strings where each index i (0 ≤ i < n) contains the string Yes if ai and bi are twins or the string No if they are not.
  14.  
  15. Input Format
  16.  
  17. The internal test cases read the following input from stdin and pass it to the function:
  18.  
  19. The first line contains an integer, n, denoting the number of elements in a.
  20.  
  21. Each line i of the n subsequent lines (where 0 ≤ i < n) contains a string describing ai.
  22.  
  23. The next line contains an integer, n, denoting the number of elements in b.
  24.  
  25. Each line i of the n subsequent lines (where 0 ≤ i < n) contains a string describing bi.
  26.  
  27. Constraints
  28.  
  29. 1 ≤ n ≤ 10^3
  30. 1 ≤ lengths of ai, bi ≤ 100
  31. ai and bi are not guaranteed to have the same length.
  32. Strings ai and bi contain lowercase letters only (i.e., a through z).
  33.  
  34. Output Format
  35.  
  36. The function must return an array of strings where each index i (0 ≤ i < n) contains the string Yes if ai and bi are twins or the string No if they are not.
  37.  
  38. Sample Input :
  39.  
  40. 2
  41.  
  42. cdab
  43.  
  44. dcba
  45.  
  46. 2
  47.  
  48. abcd
  49.  
  50. abcd
  51.  
  52.  
  53. Sample Output :
  54.  
  55. Yes
  56.  
  57. No
  58.  
  59.  
  60. Explanation :
  61.  
  62. Given a = ["cdab", "dcba"] and b = ["abcd", "abcd"], we process each element like so:
  63.  
  64. a0 = "cdab" and b0 = "abcd": We store Yes in index 0 of the return array because a0 = "cdab" → "adcb" → "abcd" = b0.
  65. a1 = "dcba" and b1 = "abcd": We store No in index 1 of the return array because no amount of operations will move a character from an odd index to an even index, so the two strings will never be equal.
  66.  
  67. We then return the array ["Yes", "No"] as our answer.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement