lcm
Given two integers, find their least common multiple (LCM). The LCM is the smallest positive integer that is divisible by both numbers.
Examples
lcm(4, 6) → 12
lcm(7, 5) → 35
Starter code
function lcm(a, b) {
}
Complexity of the optimal solution
Time O(log(min(a,b))), space O(1). The time complexity is dominated by the GCD calculation, which uses the efficient Euclidean algorithm and runs in logarithmic time. The rest of the operations are constant time.