Maximum pair GCD
Given an array of positive integers with values bounded by M (e.g. M <= 10^5), return the maximum gcd over all unordered pairs of distinct elements. The O(n^2) all-pairs gcd is too slow for large arrays; instead, for each candidate g from M down to 1, check whether at least two array elements are multiples of g using a count of values. The first g for which two multiples exist is the answer. Return 0 if the array has fewer than two elements.
Implement
max_pair_gcd(arr: list[int]) → intExamples
in
[[12,18,24]]out12What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 25 min
solution.py
InputExpectedGot
[[12,18,24]]12not run yetsample