Odd Revenue Marker Total
Context
A reporting system assigns meaning to positive odd-numbered revenue markers. Given the first and last marker numbers in a requested interval, calculate the total of every positive odd marker included by that interval. The report must answer instantly even when the bounds span a very large range.
Problem
Implement a function that returns the sum of all positive odd integers from lower_bound through upper_bound, including both endpoints when they qualify. Zero and negative integers never contribute. If lower_bound is greater than upper_bound, the interval is empty and the result is 0. Use an endpoint prefix calculation: determine the sum of qualifying odd positive integers through an endpoint, then subtract the prefix through the integer immediately before the lower bound from the prefix through the upper bound.
Examples
lower_bound = 1upper_bound = 1025lower_bound = -6upper_bound = 716lower_bound = 12upper_bound = 50Constraints
-1000000000 <= lower_bound <= 1000000000-1000000000 <= upper_bound <= 1000000000- Types:
lower_boundis int,upper_boundis int; result is int
Function signature
def sum_odd_markers(lower_bound: int, upper_bound: int) -> int
lower_boundint- The inclusive first integer in the report interval.
upper_boundint- The inclusive last integer in the report interval.
- returns int
- The exact sum of all positive odd integers in the inclusive interval, or 0 when the interval is empty or contains no positive odd integer.
Adapted from MBPP problem task_797 (CC BY 4.0). Rewritten, extended and verified by Iksha.
Notes
- The result and intermediate values may be larger than either input bound.
- Python integer arithmetic provides the required exactness.