Date: 2026-06-06
Time: 19:08
smallest-even-multiple/solution.pyThis file solves LeetCode 2413: Smallest Even Multiple. Given a positive integer n, it returns the smallest positive integer that is a multiple of both 2 and n — i.e., the LCM of n and 2.
It's a leaf module in the repo: no imports, no dependencies. Its only consumer is smallest-even-multiple/test_solution.py.
smallest_multiple(n: int) -> int — the sole public function.
[1, 150], returns the LCM of n and 2.n if n % 2 == 0 else n * 2. If n is already even, n itself is the smallest common multiple. If odd, n * 2 is.Direct mathematical insight over general-purpose algorithms. The problem is technically "find LCM(n, 2)", but since 2 is prime, the solution collapses to a parity check. No math.gcd import needed — the entire solution is a single ternary expression.
Defensive input validation. The function checks type (isinstance) and range bounds before doing any work, which is a pattern used across this repo's solutions.
Docstring with examples. The docstring includes >>> examples that double as informal documentation, though they aren't wired into a doctest runner.
smallest-even-multiple/test_solution.py (and listed as imported by ~400+ other test files in the "Imported By" section, but that list appears to be a repo-wide cross-reference artifact — those test files import their own respective solutions, not this one).1. Validate n is an int in [1, 150]. Raise ValueError if not.
2. Check parity: even → return n; odd → return n * 2.
No loops, no recursion, no branching beyond the single ternary. O(1) time and space.
n must be a Python int — floats like 6.0 are rejected by the isinstance check even though they're mathematically valid.n is already even, or n * 2 is).n (either n itself or 2n).A single ValueError with a descriptive f-string message is raised for any input outside the valid domain. No try/except, no silent fallbacks. The caller is expected to pass valid input; violations are loud.