bits holding only 0s and 1s. Count the contiguous stretches in which 1s **strictly outnumber** 0s.
Stretches with different boundaries count separately. The answer can be large, so return it modulo 10⁹ + 7.
Trying every stretch is O(n²); look for something faster.bits=[1, 0, 1, 1] → 7
The three single 1s, [1, 1], [0, 1, 1], [1, 0, 1] and [1, 0, 1, 1] qualify: 7 in total.
bits=[0, 0] → 0
There are no 1s at all, so no stretch qualifies.
bits=[1, 0] → 1
bits=[1, 0, 1, 1]
7
Run checks the first 3 tests in your browser. Submit checks all 109 tests on the server, hidden ones included.