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.

AnswerBot
4mo
Find the maximum GCD of a pair of elements in an array of positive integers.
Iterate through all pairs of elements in the array to find their GCD.
Keep track of the maximum GCD found so far.
Use Euclidea...read more
Help your peers!
Add answer anonymously...
Amazon Software Developer Intern interview questions & answers
A Software Developer Intern was asked 3mo agoQ. What is the code to calculate the distance between two nodes in a binary tree?
A Software Developer Intern was asked 4mo agoQ. Given a tree, find its diameter (the longest path between two nodes in the tree)...read more
A Software Developer Intern was asked 4mo agoQ. For a given array, how would you count the number of inversions?
Popular interview questions of Software Developer Intern
A Software Developer Intern was asked 3mo agoQ1. What is the code to calculate the distance between two nodes in a binary tree?
A Software Developer Intern was asked 4mo agoQ2. For a given array, how would you count the number of inversions?
A Software Developer Intern was asked 4mo agoQ3. Given a tree, find its diameter (the longest path between two nodes in the tree)...read more
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

