Company: Linkedin
Difficulty: medium
Given two integers a and b , determine how many integers in the range [a+1, b] have the same parity between the sum of digits in even positions ( sumEven ) and the sum of digits in odd positions ( sumOdd ). Return the count modulo 10 9 +7, as the number may be very large. Note: The digit positions in a number start from 0 (counting from the left). For example, in the number 201921: sumEven = 2 + 1 + 2 = 5 sumOdd = 0 + 9 + 1 = 10 "Same parity" means sumEven and sumOdd are both even or both odd. Example a = 8 , b = 13 . Check each integer in the range: 9: sumEven = 9, sumOdd = 0 — parity differs. 10: sumEven = 1, sumOdd = 0 — parity differs. 11: sumEven = 1, sumOdd = 1 — parity matches. 12: sumEven = 1, sumOdd = 2 — parity differs. 13: sumEven = 1, sumOdd = 3 — parity matches. There are two numbers that meet the parity requirement. Input Format a b Two lines, each containing one non-negative integer written in decimal (they may be far too large to