Skip to content

ORIGINAL CODING QUESTION

Largest shared batch divisor

Return the greatest positive integer dividing every supplied positive batch size.

Open practice workspace

Original exercise · easy. Editorial role relevance does not imply a company has asked this question.

Input and output

n, then n integer values. Print one integer as described.

Constraints

1 ≤ n ≤ 200; 1 ≤ batch size ≤ 10000.

Example 1

Input

3 12 18 24

Output

6

The greatest shared divisor is 6.

Example 2

Input

2 7 11

Output

1

Only 1 divides both.

Explain your approach

Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?

Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.

Hint 1

A divisor shared by all values is shared by every accumulated pair.

Hint 2

Use the Euclidean algorithm.

Hint 3

Fold gcd over the values.

Practice this question

Save your work privately, explain decisions and return to your revision queue.

Open practice workspaceBrowse the question library →