Problem · Math
Find Pair with Maximum GCD
Learn this problemProblem statement
Given an integer array arr, choose two elements at distinct indices and return the maximum possible greatest common divisor (GCD) of the pair.
Function
findPairWithMaximumGCD(arr: int[]) → intExamples
Example 1
arr = [1, 2, 3, 4, 8, 9]return = 4The pair (4, 8) has GCD 4, which is the maximum possible.
Example 2
arr = [1, 2, 3, 5]return = 1The pair (3, 5) has GCD 1. Every pair in the array has GCD 1.
Constraints
arrcontains at least two elements.- Every element of
arris a positive 32-bit integer.