Whenever you're ready, walk me through how you'd approach this.
How would you count the total number of valid substrings in a binary array consisting of only 0s and 1s?
Assume a valid substring contains an equal number of 0s and 1s. Provide an efficient implementation, explain its time and space complexity, and include tests for empty, uniform, alternating, and skewed arrays. The solution should process the array in one pass and avoid enumerating every substring.