
Given two integers ‘LOW’ and ‘HIGH’, your task is to find the total number of odd integers between the interval [LOW, HIGH]. Here both ‘LOW’ and ‘HIGH’ are inclusive.
The first line of input contains an integer ‘T’, denoting the number of test cases.
The first line of each test case contains two space-separated integers, ‘LOW’ and ‘HIGH’, denoting the start and end of the interval respectively.
Output format:
For each test case, print a single line containing a single integer denoting the total count of odd numbers present between ‘Low’ and ‘High’ both inclusively.
The output for each test case will be printed in a separate line.
Note:
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 1000
0 <= LOW<= 10 ^ 9
LOW <= HIGH <= 10 ^ 9
Where ‘T’ represents the number of test cases, ‘LOW’ represents the start of the interval and ‘HIGH’ represents the end of the interval.
Time Limit: 1 sec.
2
1 6
5 10
3
3
For the first test case,
All integers between LOW = 1 and HIGH = 6 are [1, 2, 3, 4, 5, 6] and the odd numbers present between them are [1, 3, 5]. So the output will be 3.
For the second test case,
All integers between LOW = 5 and HIGH = 10 are [5, 6, 7, 8, 9, 10] and the odd numbers present between them are [5, 7, 9]. So the output will be 3.
2
3 7
8 10
3
1
Odd numbers are those for which when divided by 2 does not leave a remainder 0.
Approach:
Algorithm:
O(N), where ‘N’ is equal to (High - Low + 1).
Since the length of the interval will be N = High - Low + 1 and traversing over N elements will take O(N) time. So the overall time complexity will be O(N).
O(1).
Since constant space is being used. So overall space complexity will be O(1).