- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Suppose we have two non-negative numbers left and right. We have to find the number of odd numbers between left and right (inclusive).

So, if the input is like left = 3, right = 15, then the output will be 7 because there are 7 odd numbers in range, these are [3,5,7,9,11,13,15], there are 7 elements.

To solve this, we will follow these steps −

if left is odd or right is odd, then

return 1 + quotient of (right-left) / 2

otherwise,

return quotient of (right-left) / 2

Let us see the following implementation to get better understanding −

def solve(left, right): if left % 2 == 1 or right % 2 == 1: return (right-left) // 2 + 1 else: return (right-left) // 2 left = 3 right = 15 print(solve(left, right))

3, 15

7

- Related Questions & Answers
- Python Program to Print Numbers in an Interval
- Python program to print all odd numbers in a range
- Python program to print all Prime numbers in an Interval
- Python program to Count Even and Odd numbers in a List
- Program to find count of numbers having odd number of divisors in given range in C++
- How to Print all Prime Numbers in an Interval using Python?
- Golang Program to Print Odd Numbers Within a Given Range
- 8085 program to count total odd numbers in series of 10 numbers
- Python Program to Find All Numbers which are Odd and Palindromes Between a Range of Numbers
- Count Odd and Even numbers in a range from L to R in C++
- C++ program to find numbers with K odd divisors in a given range
- Python program to print odd numbers in a list
- PHP program to find the sum of odd numbers within a given range
- Python program to count unset bits in a range.
- Program to find one minimum possible interval to insert into an interval list in Python

Advertisements