GCD of the Two Extreme Array Values. Find the minimum and maximum values in nums and return their greatest common divisor, meaning the largest positive integer that divides both without remainder. Interior entries do not otherwise affect the result.
### Problem
Return the greatest common divisor of the minimum and maximum entries in `nums`. This is the largest positive integer dividing both of those two extreme values without remainder.
```cpp
class Solution {
public:
int findGCD(vector<int>& nums);
};
```
### Examples
**Example 1:**
```text
nums = [6,9,18]
Output: 6
Explanation: The extreme values are 6 and 18.
```
**Example 2:**
```text
nums = [8,11,15]
Output: 1
Explanation: The extremes 8 and 15 are coprime.
```
### Constraints
- `2 <= nums.length <= 1000`.
- `1 <= nums[i] <= 1000`.
### Clarifying Questions
The requested value is the GCD of the minimum and maximum, not of all entries.
```hint Inspect the structure
Which two values must be retained while scanning the input?
```
### Reasoning checkpoints
- Use the two specified extrema as the required pair and justify both divisibility and maximality of the returned value.
- Handle equal extrema and distinguish this task from taking the GCD of the entire array.
### Optional extensions
Give an input where the GCD of all entries differs from that of the extrema.
Overview: GCD of the Two Extreme Array Values. Find the minimum and maximum values in nums and return their greatest common divisor, meaning the largest positive integer that divides both without remainder. Interior entries do not otherwise affect the result.
Return the greatest common divisor of the minimum and maximum entries in nums. This is the largest positive integer dividing both of those two extreme values without remainder.
class Solution {
public:
int findGCD(vector<int>& nums);
};
Examples
Example 1:
nums = [6,9,18]
Output: 6
Explanation: The extreme values are 6 and 18.
Example 2:
nums = [8,11,15]
Output: 1
Explanation: The extremes 8 and 15 are coprime.
Constraints
2 <= nums.length <= 1000
.
1 <= nums[i] <= 1000
.
Clarifying Questions Guidance
The requested value is the GCD of the minimum and maximum, not of all entries.
Reasoning checkpoints
Use the two specified extrema as the required pair and justify both divisibility and maximality of the returned value.
Handle equal extrema and distinguish this task from taking the GCD of the entire array.
Optional extensions
Give an input where the GCD of all entries differs from that of the extrema.