Skip to content
RED SAGSkills
easy15 ptsmath

Equal Team Split

Several departments have groups[i] people each. You want to split every department into teams of the same size t with nobody left over, using one t for all departments.

Return the largest possible t.

Example 1

Input: groups = [12, 18, 24]
Output: 6

Example 2

Input: groups = [7, 13]
Output: 1

Constraints

  • 1 <= groups.length <= 10^5
  • 1 <= groups[i] <= 10^9
Hint 1

The answer is the greatest common divisor of all group sizes.

Hint 2

Use the Euclidean algorithm and fold it across the array.

Discussion 0

Join free to post in the discussion.

Good practice for: Frontend Developer, Backend Developer, Full Stack Developer, Mobile App Developer, Automation Test Engineer

Run checks your code on 2 sample tests. Submit runs all 7 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.