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
Inputnums = [2,5,6,9,10]
Output2
The smallest number is 2, the largest number is 10, and their greatest common divisor is 2.
Example 2
Inputnums = [7,5,6,8,3]
Output1
The 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

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate