The problem of finding the number of sub-arrays with odd sum, commonly identified as LeetCode 1524, challenges developers and mathematicians alike to efficiently count contiguous subarrays whose element sum yields an odd result. Given an integer array, a subarray is any contiguous segment of the original array, and the task is to determine how many of these segments produce an odd sum. This seemingly simple counting problem reveals deep connections to parity, prefix sums, and algorithmic optimization, making it an excellent case study for both beginners and experienced programmers looking to sharpen their analytical skills.
Understanding the Problem Statement
At its core, the problem provides an array of integers (which may include positive, negative, or zero values) and asks for the total count of subarrays where the sum of elements is odd. A subarray is defined by a contiguous range of indices (i, j] where 0 ≤ i < j ≤ n. To give you an idea, given `arr = [1, 3, 5