Skip to the code
+10 XP

#635 Shared Spacing Unit

easy

A design-token audit lists the pixel spacings used on a page in spacings. The team wants the largest base unit that every spacing is a whole multiple of.

Write sharedSpacingUnit(spacings) that returns the greatest common divisor of all the numbers in spacings.

Example 1

Input: spacings = [8,12,20]
Output: 4

8, 12, and 20 are all multiples of 4, and no larger number divides all three.

Example 2

Input: spacings = [16]
Output: 16

With one spacing, the unit is the spacing itself.

Constraints

  • 1 <= spacings.length <= 10^5
  • 1 <= spacings[i] <= 10^12
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).