All problems
1141EasyMath

Odd Numbers Inside a Range

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1523Count Odd Numbers in an Interval Range

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

Return how many odd numbers lie in the range from low to high, counting both ends.

Examples

Example 1

Input
low = 1, high = 10
Output
5

The odd numbers from 1 to 10 are 1, 3, 5, 7 and 9.

Example 2

Input
low = 2, high = 2
Output
0

The range holds a single number and it is even.

Example 3

Input
low = 5, high = 5
Output
1

The range holds a single number and it is odd.

Constraints

  • 0 <= low <= high <= 10^9

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def count_odds(low: int, high: int) -> int:
Java
public int countOdds(int low, int high)
September 7
Apply