Remove One Element solution codechef

Remove One Element codechef solution

Alice has an array AA consisting of NN distinct integers. Bob takes exactly N−1N−1 elements from this array and adds a positive integer XX (i.e. X>0X>0) to each of these numbers and then shuffles them to form a new array BB of length N−1N−1.

You are given both arrays AA and BB. You have to identify the value of XX chosen by Bob. If there are multiple possible values of XX, print the smallest of them. It is guaranteed that for the given input, there exists at least one possible value of XX.

Note: Since the input is large, prefer using fast input methods.

Input Format Remove One Element solution codechef

  • The first line of input contains a single integer TT denoting the number of test cases. The description of TT test cases follows.
  • Each test case contains 33 lines of input.
  • The first line contains an integer NN – the length of array AA.
  • The second line contains NN space-separated integers A1,A2,…,ANA1,A2,…,AN, denoting the array AA.
  • The third line contains N−1N−1 space-separated integers B1,B2,…,BN−1B1,B2,…,BN−1, denoting the array BB.

Output Format Remove One Element solution codechef

For each test case, output the value of XX chosen by Bob. In case there are multiple possible values of XX, print the smallest of them.

Constraints Remove One Element solution codechef

  • 1≤T≤71≤T≤7
  • 2≤N≤1052≤N≤105
  • 1≤Ai≤1091≤Ai≤109
  • 1≤Bi≤2⋅1091≤Bi≤2⋅109
  • A1,A2,…,ANA1,A2,…,AN are pairwise distinct.
  • B1,B2,…,BN−1B1,B2,…,BN−1 are pairwise distinct.
  • Sum of NN over all test cases does not exceed 5⋅1055⋅105.

Sample Input 1 

3
4
1 4 3 8
15 8 11
2
4 8
10
2
2 4
3

Sample Output 1  Remove One Element solution codechef

7
2
1

Explanation

Test case 11: Bob takes the elements {1,4,8}{1,4,8} and adds 77 to them to obtain a new sequence {8,11,15}{8,11,15}. There is no other value of XX that can be added to the elements of AA to get BB.

Test case 33: There is only one option with Bob to consider, i.e. to take element {2}{2} and add 11 to it to get array BB. If he takes element {4}{4}, he will have to add −1−1 which is not allowed.

Also See – Grid Path codechef solution

Magical Flips solution codechef

Chef and Professor solution codechef- python, java, c++

Leave a Comment

Your email address will not be published.