PracticeMath

Odd Revenue Marker Total

EasyMathcountingfilteringcomparison Time not estimated Not started

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

Example 1
Input: lower_bound = 1upper_bound = 10
Output: 25
Explanation: For bounds 1 and 10, the executed output is 25.
Example 2
Input: lower_bound = -6upper_bound = 7
Output: 16
Explanation: For bounds -6 and 7, the executed output is 16.
Example 3
Input: lower_bound = 12upper_bound = 5
Output: 0
Explanation: For bounds 12 and 5, the executed output is 0 because the interval is empty.

Constraints

  • -1000000000 <= lower_bound <= 1000000000
  • -1000000000 <= upper_bound <= 1000000000
  • Types: lower_bound is int, upper_bound is int; result is int

Function signature

def sum_odd_markers(lower_bound: int, upper_bound: int) -> int
lower_bound int
The inclusive first integer in the report interval.
upper_bound int
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.
Approved · t2-abs_197_v114 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1