Given an integer array, find the greatest common divisor of its largest and smallest elements.
You are given an integer array nums. Your task is to compute the greatest common divisor (GCD) of the smallest and largest values in the array.
In other words, let:
mn be the minimum value in numsmx be the maximum value in numsReturn gcd(mn, mx).
nums.nums.nums.length >= 1Example 1
Input
nums = [2,5,6,9,10]
Output
2
Explanation
The minimum is 2 and the maximum is 10. Their GCD is 2.
Example 2
Input
nums = [7,5,6,8,3]
Output
1
Explanation
The minimum is 3 and the maximum is 8. Their GCD is 1.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.