2413. Smallest Even Multiple LeetCode Solution

In this guide, you will get 2413. Smallest Even Multiple LeetCode Solution with the best time and space complexity. The solution to Smallest Even Multiple problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.

Table of Contents

  1. Problem Statement
  2. Complexity Analysis
  3. Smallest Even Multiple solution in C++
  4. Smallest Even Multiple solution in Java
  5. Smallest Even Multiple solution in Python
  6. Additional Resources
2413. Smallest Even Multiple LeetCode Solution image

Problem Statement of Smallest Even Multiple

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

Example 1:

Input: n = 5
Output: 10
Explanation: The smallest multiple of both 5 and 2 is 10.

Example 2:

Input: n = 6
Output: 6
Explanation: The smallest multiple of both 6 and 2 is 6. Note that a number is a multiple of itself.

Constraints:

1 <= n <= 150

Complexity Analysis

  • Time Complexity: O(1)
  • Space Complexity: O(1)

2413. Smallest Even Multiple LeetCode Solution in C++

class Solution {
 public:
  int smallestEvenMultiple(int n) {
    return n * (n % 2 + 1);
  }
};
/* code provided by PROGIEZ */

2413. Smallest Even Multiple LeetCode Solution in Java

class Solution {
  public int smallestEvenMultiple(int n) {
    return n * (n % 2 + 1);
  }
}
// code provided by PROGIEZ

2413. Smallest Even Multiple LeetCode Solution in Python

class Solution:
  def smallestEvenMultiple(self, n: int) -> int:
    return n * (n % 2 + 1)
# code by PROGIEZ

Additional Resources

Happy Coding! Keep following PROGIEZ for more updates and solutions.