← ALL NOTES
Math

1523. Count Odd Numbers in an Interval Range

Count odd numbers in [low, high] inclusive. A closed-form prefix count plus a difference gives O(1): the number of odds in [1, x] is (x+1)/2 (integer division), so the answer is odds(high) −…

Loading…