Calculate the Greatest Common Divisor (GCD) of two positive integers using the Euclidean algorithm. The GCD is the largest number that divides both numbers without leaving a remainder. Return null if either number is null or not positive.
Examples:
Input: a = 48, b = 18
Output: 6
Explanation: 6 is the largest number that divides both 48 and 18
Input: a = 17, b = 5
Output: 1
Explanation: Coprime numbers share no common divisors except 1
Input: a = 100, b = 25
Output: 25
Explanation: 25 divides evenly into 100
Input: a = 0, b = 5
Output: null
Explanation: Zero is not positive, return null
Input: a = null, b = 5
Output: null
Explanation: Null input, return null
Apex Code Editor
Welcome to Lightning Challenge!
How It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay July 2026
Contest runs July 1 - 31. Complete challenges to climb the leaderboard!
Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.