Given an integer array nums of size N and an integer K. Find the largest positive number less than equal to 10^9 such that at least K numbers from the array nums are divisible by it.
Complete the solve function. This function takes the following 3 parameters and returns the required answer;
•M. Represents the size of array nums
•K: Represents the integer K
• nums: Represents the elements of array nums
Input format for custom testing
Note: Use this input format if you are testing against custom input or writing code in a language where we don't provide boilerplate code. The first line contains T. which represents the number of test cases.
For each test case:
For each test case in a new line, print the required answer.
1 <= T ≤ 1000
1<= N <= 10^5
1<=K≤N
O < numsi ≤ 10^6, 1 <= i <= N
Σ 1<=i<=T Ni <= 10^5
Sample Input
2
5
3
12 16 32 2 45
5
3
12 16 32 2 0
Sample Output
4
16
The first line denotes T=2, denoting the number of test cases.
The first test case
Given 2 arrays A and B You can apply the given operation on array A
An operation on Array A is
• Select an integer such that. 1 S K S floor(N/2). Where N is the size of the
array
•Swap the prefix and suffix of length K of the array A.
Notes
•The prefix of an array of length K is the subarray of the array conteining the
first K elements In the order arranged in the array.
The suffix of an array of length K Is the subarray of the array containing the
last K element in the order arranged in the array.
check whether It is possible to convert Array A to Array B. If possible return 1, else -1
Complete the function Solve which takes three parameters as arguments and returns 1 if A is convertible to B is possible, else return -1.
Sample
input 2
5
5
1
1 0 0 0
2
1 2 4 8 16
5
3
1 0 0 8 16
Sample output 2
1000000000
8
16
2