Return the Least Positive Number Divisible by Two and n

Quick Overview

Return the smallest positive integer divisible by both the given positive number and two.

Return the Least Positive Number Divisible by Two and n

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem For positive integer n, return the smallest positive integer divisible by both n and 2. A number is allowed to be its own multiple. ```cpp class Solution { public: int smallestEvenMultiple(int n); }; ``` ### Examples **Example 1:** ```text Input: n = 9 Output: 18 Explanation: Nine is odd, so its first even positive multiple is 18. ``` **Example 2:** ```text Input: n = 14 Output: 14 Explanation: Fourteen already satisfies both divisibility requirements. ``` ### Constraints - `1 <= n <= 150`. ### Clarifying Questions - Must the result be positive? Yes. - Can `n` itself be the answer? Yes, if it meets both divisibility conditions. - Is zero an allowed input? No; `n >= 1`. ```hint Check the boundary Check the smallest permitted input and a number already divisible by two. ```

Overview: Return the smallest positive integer divisible by both the given positive number and two.

Google logo
Google
Source window: 0–6 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

For positive integer n, return the smallest positive integer divisible by both n and 2. A number is allowed to be its own multiple.

class Solution {
public:
    int smallestEvenMultiple(int n);
};

Examples

Example 1:

Input: n = 9
Output: 18
Explanation: Nine is odd, so its first even positive multiple is 18.

Example 2:

Input: n = 14
Output: 14
Explanation: Fourteen already satisfies both divisibility requirements.

Constraints

  • 1 <= n <= 150 .

Clarifying Questions Guidance

  • Must the result be positive? Yes.
  • Can n itself be the answer? Yes, if it meets both divisibility conditions.
  • Is zero an allowed input? No; n >= 1 .