Number theory · Easy
A data importer splits several record counts into equal-sized batches without a remainder. Counts can be signed adjustments; their sign does not affect divisibility. Zero contributes no additional constraint.
Return the greatest non-negative integer that divides every count without a remainder.
Input
Call
- Implement solve(input) and return the result. The provided adapter handles JSON input and output.
Input shape
{ nums: integer[] }
Fields
- nums is an array of signed integers in its original order. Equal values at different indexes are separate entries.
Output
Return value
- Return the GCD of absolute values. Empty input and all-zero input return 0.
- Return one integer, not batches or divisors.
Constraints
- 0 <= nums.length <= 100000; -1000000000 <= nums[i] <= 1000000000.
- All requested totals and counts fit exactly in a safe JSON integer.
Examples
Example 1
{
"nums": [
-12,
0,
18
]
}Returns
6Example 2
{
"nums": [
0,
0
]
}Returns
0Required complexity
O(n log M) time and O(1) auxiliary space, where M is the largest magnitude