Smallest Even Multiple - Problem

Given a positive integer n, return the smallest positive integer that is a multiple of both 2 and n.

In other words, find the smallest number that is divisible by both 2 and n.

Input & Output

Example 1 — Odd Number
$ Input: n = 5
Output: 10
💡 Note: Since 5 is odd, the smallest multiple of both 2 and 5 is 2×5 = 10. We can verify: 10÷2 = 5 and 10÷5 = 2.
Example 2 — Even Number
$ Input: n = 6
Output: 6
💡 Note: Since 6 is even, it's already divisible by 2. The smallest multiple of both 2 and 6 is 6 itself. We can verify: 6÷2 = 3 and 6÷6 = 1.
Example 3 — Small Odd
$ Input: n = 1
Output: 2
💡 Note: Since 1 is odd, the smallest multiple of both 2 and 1 is 2×1 = 2. We can verify: 2÷2 = 1 and 2÷1 = 2.

Constraints

  • 1 ≤ n ≤ 150

Visualization

Tap to expand
Smallest Even Multiple: Find LCM of 2 and nInput: n = 5Find multiples:2: 2,4,6,8,10...5: 5,10,15,20...Output: 10Mathematical Rule: If n is odd → LCM(2,n) = 2×nIf n is even → LCM(2,n) = nSince 5 is odd: 2 × 5 = 10Verify: 10 ÷ 2 = 5 ✓ and 10 ÷ 5 = 2 ✓
Understanding the Visualization
1
Input
Given positive integer n
2
Process
Find LCM of 2 and n
3
Output
Return smallest multiple
Key Takeaway
🎯 Key Insight: The LCM of 2 and n is simply n if n is even, or 2n if n is odd
Asked in
Amazon 15 Apple 8
31.5K Views
Low Frequency
~5 min Avg. Time
850 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen