š§®
Least Common Multiple
Least Common Multipleģ¬ģ ģź³ ė¦¬ģ¦ +10pts
Problem
Write a function that returns the least common multiple of two numbers.
Examples
Input:
lcm(4, 6)Output:
12Explanation
ģ“ ė¬øģ ė **GCD넼 ķģ©**ķģ¬ ģµģ공배ģ넼 구ķė ė°©ė²ģ ķģµķ©ėė¤. ## ķµģ¬ ź°ė : ģµģ공배ģ (LCM) ģµģ공배ģė ė ģģ ź³µķµė ė°°ģ ģ¤ ź°ģ„ ģģ ģģ ėė¤. ### GCDģ LCMģ ź“ź³ ```javascript LCM(a, b) = (a * b) / GCD(a, b) ``` ### ģ ź·¼ ė°©ė² ```javascript function lcm(a, b) { const gcd = (x, y) => y ? gcd(y, x % y) : x; return (a * b) / gcd(a, b); } ``` ###...
View detailed explanation āKey Concepts
ģµģ공배ģ GCD ķģ© ģķ ź³µģ ģ¤ė²ķė”ģ° ė°©ģ§
Time: O(log(min(a,b))) Space: O(1)
solution.js
Ctrl + Enter
Run tests to see results here.