- Odd number
- 2024-03-29 11:56:51 @
Prerequisite : Basic math
Problem statement summary : You are given a number N.You need to find out how many numbers between 1 to N (inclusive) are ODD.
Solution : We know that if a number is divided by 2 and if you get reminder 1, then we call it an odd number. More formally, if N % 2 = 1, it’s an odd number. Let’s see an example,
If N = 5, all possible number between 1 to N are : 1, 2, 3,4 ,5 and 1, 3 , 5 are odd numbers.
We can see that , no matter which number is N, there is always (N+1)/2 odd numbers.
Time Complexity : O(1)
0 comments
No comments so far...
Information
- ID
- 1041
- Difficulty
- 1
- Category
- Beginners Click to Show
- Tags
- (None)
- # Submissions
- 64
- Accepted
- 44
- Accepted Ratio
- 69%
- Uploaded By