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
Calculate the GCD of each pair using Euclidean algorithm
Keep track of the ...read more
Help your peers!
Add answer anonymously...
PhonePe Software Developer interview questions & answers
A Software Developer was asked 6mo agoQ. Why do you want to join?
A Software Developer was asked 8mo agoQ. Given a graph, write a function to perform a Breadth-First Search (BFS) traversa...read more
A Software Developer was asked Q. Insertion in AVL Tree Problem Statement You are required to implement an AVL Tre...read more
Popular interview questions of Software Developer
A Software Developer was asked 6mo agoQ1. Why do you want to join?
A Software Developer was asked Q2. Insertion in AVL Tree Problem Statement You are required to implement an AVL Tre...read more
A Software Developer was asked Q3. Unlock the Briefcase Problem Statement You have a briefcase secured by a lock wi...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

