Trains the technique from
LeetCode 1979Find Greatest Common Divisor of ArrayThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A drawer holds a jumble of sprockets and nums[i] is the tooth count of the i-th one. The counts arrive in no particular order and two sprockets may well carry the same number of teeth.
A workshop jig needs the two extremes of the drawer: the sprocket with the fewest teeth and the sprocket with the most. Return the largest positive integer that divides both of those two tooth counts with nothing left over.
When one tooth count is both the smallest and the largest, the two extremes are the same value and that value is its own answer.
Example 1
The extremes are 6 and 15. Both are divisible by 1 and by 3, and 3 is the larger of the two.
Example 2
The extremes are 4 and 15, which share no divisor above 1.
Example 3
Both extremes are 8, and 8 divides itself.
Example 4
The fewest teeth is 7 and the most is 28; 7 divides 28 exactly, so 7 is the answer.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def sprocket_common_divisor(teeth: list[int]) -> int:public int sprocketCommonDivisor(int[] teeth)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.