Find Greatest Common Divisor of Array
Given an integer array nums, return the greatest common divisor of the smallest number and largest number in nums.
The greatest common divisor of two numbers is the largest positive integer that evenly divides both numbers.
Example 1
Input
nums = [2,5,6,9,10]Output
2The smallest number is 2, the largest number is 10, and their greatest common divisor is 2.
Example 2
Input
nums = [7,5,6,8,3]Output
1The smallest number is 3, the largest number is 8, and their greatest common divisor is 1.
Constraints
- 2 <= nums.length <= 1000
- 1 <= nums[i] <= 1000
Asked at 5 companies
Practice questions like this out loud in a mock coding interview with a live AI interviewer. First one free.