Ctrl K

GCD of the Extremes

Easy
You are given an array of positive integers values. Take its smallest and largest numbers and return their greatest common divisor: the largest positive integer that divides both of them evenly.
Example 1
values=[12, 30, 18, 20] → 6

The minimum is 12, the maximum is 30, and their GCD is 6.

Example 2
values=[9, 4, 7] → 1

4 and 9 share no divisor except 1.

Example 3
values=[8, 8] → 8
Constraints
  • 2 ≤ len(values) ≤ 1000
  • 1 ≤ values[i] ≤ 1000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsEven Piles of Cards EasyLargest Prime on the Diagonals EasyCoprime Digit Pairs EasyWhere the Product Adds Up EasyPrimes Below a Bound Medium
loading Python…
Input
values=[12, 30, 18, 20]
Expected
6

Run checks the first 3 tests in your browser. Submit checks all 102 tests on the server, hidden ones included.