Find the greatest common divisor
Given exactly two integers, return their nonnegative greatest common divisor, with gcd(0,0) defined as 0. Inputs are valid JSON and must not be modified unless the algorithm uses a local copy. This exercise probes typed data modeling, boundary handling, and algorithm selection.
Input
One JSON value: number[]. See the sample for its exact shape.
Output
One compact JSON value of type number. Strings include JSON quotes; arrays preserve the specified order.
Constraints
Array/string lengths are 0 to 10000 unless stated otherwise. Numbers are integers in [-1000000,1000000]; all computed results fit the safe integer range.
Example
Input
[48,18]
Output
6
Example 2 input
[1000000,100]
Output
100
Checks a boundary or contrasting case beyond the public examples.
Public test cases (2)
Input
[48,18]
Expected output
6
Input
[0,0]
Expected output
0
Hints (2)
- Start with the required output order and the empty-input behavior.
- Use the Euclidean remainder recurrence
Target complexity: time O(log(max(abs(a),abs(b))+1)) · space O(1)
