Odd Even

Easy
0/40
16 upvotes
Asked in company
BigDataLogin

Problem statement

You are given an integer 'N'.


Return 'odd' if the given number 'N' is odd, else return 'even'.


For Example:
N=5

Output: odd
Detailed explanation ( Input/output format, Notes, Images )
Input format:
The first line contains an integer 'N’, denoting the number.
Output Format:
The output contains a string “odd” or “even”.
Note:-
You don’t need to print anything. Just implement the given function.  
Sample Input 1:
9
Sample Output 1:
odd
Sample Input 2:
6
Sample Output 2:
even
Constraints:
1 <= N <= 10^4
Time Limit: 1 sec
Hint

Using modulus

Approaches (2)
Brute force

Approach:

Find the modulus of ‘N’ with 2. If it comes out 1 then it's “odd” else “even”.

 

Algorithm:

  • If (N mod 2) is equal to 1
    • return “odd”
  • else
    • return “even”
Time Complexity

O(1)

 

We are simply using if-else statement therefore complexity is O(1).

Space Complexity

O(1)

 

No extra space is used.

Code Solution
(100% EXP penalty)
Odd Even
Full screen
Console