Max GCD Pair Problem Statement
Given an array of positive integers, determine the Greatest Common Divisor (GCD) of a pair of elements such that it is the maximum among all possible pairs in the array. The GCD of two numbers a and b is the greatest number x that divides both a and b without leaving a remainder.
Example:
Input:
arr = [1, 5, 2, 3, 4]
Output:
2
Explanation:
The maximum GCD found is 2, which is obtained from the pair (2, 4). All other pairs yield a GCD of 1.
Input:
The first line of input contains a single integer 'T', denoting the number of test cases. Each test case includes: - An integer 'N' indicating the size of the array. - 'N' space-separated positive integers that represent the elements of the array.
Output:
For each test case, output the maximum GCD value on a new line.
Constraints:
- 1 <= T <= 10
- 2 <= N <= 10^4
- 1 <= ARR[i] <= 10^5
Note:
No input or output functions need to be handled; implement the function to solve the problem as described.
Be the first one to answer
Add answer anonymously...
Top Apple Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app