Problem Description
Given a positive integer n, return the smallest positive integer that is a multiple of both 2 and n.
Key Insights
- The result must be even since it is a multiple of 2.
- If n is even, then n is already the smallest even multiple.
- If n is odd, multiplying n by 2 yields the smallest even multiple.
Space and Time Complexity
Time Complexity: O(1) since the solution involves a constant number of operations. Space Complexity: O(1) as we only use a constant amount of space.
Solution
The problem is solved by checking if n is even or odd. If n is even, n is returned because it is a multiple of 2. If n is odd, then multiplying n by 2 gives the smallest even multiple. This solution uses a simple conditional check and arithmetic operation without extra data structures, achieving O(1) time and space complexity.