Leetcode 2413: Smallest Even Multiple

grid47
grid47
Exploring patterns and algorithms
Mar 10, 2024 3 min read

Given a positive integer ’n’, return the smallest positive integer that is a multiple of both 2 and ’n'.
Problem
Approach
Steps
Complexity
Input: The input consists of a single integer 'n'.
Example: n = 7
Constraints:
• 1 <= n <= 150
Output: Return the smallest integer that is a multiple of both 2 and 'n'.
Example: Output: 14
Constraints:
Goal: The goal is to find the smallest integer that is divisible by both 2 and 'n'.
Steps:
• 1. Check if 'n' is already divisible by 2.
• 2. If 'n' is even, return 'n'.
• 3. If 'n' is odd, return 'n * 2' because the next multiple of both 2 and 'n' will be twice 'n'.
Goal: The solution must efficiently handle values of 'n' up to 150.
Steps:
• 1 <= n <= 150
Assumptions:
• The input is a positive integer.
• The problem ensures that 'n' is always between 1 and 150.
Input: n = 7
Explanation: For 'n' = 7, the smallest multiple of both 2 and 7 is 14. For 'n' = 6, since 6 is already divisible by 2, the result is 6.

Link to LeetCode Lab


LeetCode Solutions Library / DSA Sheets / Course Catalog
comments powered by Disqus