Back to Edit Distance

Given 2 permutations of integers from 1 to N, you need to find the minimum number of operations necessary to change both or any one of them in such a way that they become exactly same. Here only two operations are allowed: either you can delete an integer from any position or you can insert an integer into any position, but replacing one integer by another one is not allowed. Say,N =5andthepermutationsare{1,3,5,4,2}and{1,5,4,3,2}. Thenweneedjust2 operations: we need to delete 3 from the 2nd position and insert it in the 4th position of the first permutation, or we can delete 3 from both the permutations, which also needs two operations. Input First line of the input contains a positive integer T (T ≤ 40). Each of the following T cases contains 3 lines for each case: the 1st line contains a single integer N (1 ≤ N ≤ 200, 000) and the next two lines contain the two permutations of the integers. Output Foreachcase,printalineoftheform‘Case : ’,wherexisthecasenumberandyisthe number of operations necessary to covert the 1st permutation to the 2nd permutation. Sample Input 2 5 13542 15432 4 1243 3421 Sample Output Case 1: 2 Case 2: 6