Count Odd Integers in an Inclusive Range

Quick Overview

Count Odd Integers in an Inclusive Range. Return how many odd integers lie between nonnegative low and high,inclusive.

Count Odd Integers in an Inclusive Range

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Return how many odd integers lie between nonnegative low and high,inclusive. ```cpp class Solution { public: int countOdds(int low, int high); }; ``` ### Examples **Example 1:** ```text Input: low = 0, high = 4 Output: 2 Explanation: The odd values are1 and3; zero is even. ``` **Example 2:** ```text Input: low = 5, high = 5 Output: 1 Explanation: The single included value5 is odd. ``` ### Constraints - `0 <= low <= high <= 1000000000`. ### Contract considerations Handle both endpoints as inclusive, including zero and one-value intervals. ```hint Read the boundary condition Both endpoints are included. Check zero as a lower endpoint and one-value ranges of either parity. ``` ### Boundary reminders Handle both endpoints as inclusive, including zero and one-value intervals.

Overview: Count Odd Integers in an Inclusive Range. Return how many odd integers lie between nonnegative low and high,inclusive.

Amazon logo
Amazon
Source window: 0–6 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return how many odd integers lie between nonnegative low and high,inclusive.

class Solution {
public:
    int countOdds(int low, int high);
};

Examples

Example 1:

Input: low = 0, high = 4
Output: 2
Explanation: The odd values are1 and3; zero is even.

Example 2:

Input: low = 5, high = 5
Output: 1
Explanation: The single included value5 is odd.

Constraints

  • 0 <= low <= high <= 1000000000 .

Contract considerations

Handle both endpoints as inclusive, including zero and one-value intervals.

Boundary reminders

Handle both endpoints as inclusive, including zero and one-value intervals.