1523. Count Odd Numbers in an Interval Range LeetCode Solution

In this guide, you will get 1523. Count Odd Numbers in an Interval Range LeetCode Solution with the best time and space complexity. The solution to Count Odd Numbers in an Interval Range problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.

Table of Contents

  1. Problem Statement
  2. Complexity Analysis
  3. Count Odd Numbers in an Interval Range solution in C++
  4. Count Odd Numbers in an Interval Range solution in Java
  5. Count Odd Numbers in an Interval Range solution in Python
  6. Additional Resources
1523. Count Odd Numbers in an Interval Range LeetCode Solution image

Problem Statement of Count Odd Numbers in an Interval Range

Given two non-negative integers low and high. Return the count of odd numbers between low and high (inclusive).

Example 1:

Input: low = 3, high = 7
Output: 3
Explanation: The odd numbers between 3 and 7 are [3,5,7].
Example 2:

Input: low = 8, high = 10
Output: 1
Explanation: The odd numbers between 8 and 10 are [9].

Constraints:

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

Complexity Analysis

  • Time Complexity: O(1)
  • Space Complexity: O(1)

1523. Count Odd Numbers in an Interval Range LeetCode Solution in C++

class Solution {
 public:
  int countOdds(int low, int high) {
    return (high + 1) / 2 - low / 2;
  }
};
/* code provided by PROGIEZ */

1523. Count Odd Numbers in an Interval Range LeetCode Solution in Java

N/A
// code provided by PROGIEZ

1523. Count Odd Numbers in an Interval Range LeetCode Solution in Python

N/A
# code by PROGIEZ

Additional Resources

Happy Coding! Keep following PROGIEZ for more updates and solutions.