Given a **binary array**, find the total number of subarrays with the ratio of 0's and 1's equal to x:y. ↵
↵
Constraints:↵
↵
_n = arr.length_↵
↵
_2<=n<=1e5_↵
↵
_1<=x,y<=n_↵
↵
**Example:** ↵
**arr = [0,1,0,1]**↵
**x = 1**↵
**y = 1**↵
↵
**Output: 4**↵
↵
Explanation:↵
The four possible subarrays are as follows: ↵
↵
[0 1] 0 1 --> [0,1]↵
↵
0 [1 0] 1 --> [1,0]↵
↵
0 1 [0 1] --> [0,1]↵
↵
[0 1 0 1] --> [0,1,0,1]↵
↵
With the given constraints, expecting solution no worse than O(n)↵
↵
P.s: Maybe the problem can be solved using the sliding window technique. But unable to apply it due to ratio constraint.
↵
Constraints:↵
↵
_n = arr.length_↵
↵
_2<=n<=1e5_↵
↵
_1<=x,y<=n_↵
↵
**Example:** ↵
**arr = [0,1,0,1]**↵
**x = 1**↵
**y = 1**↵
↵
**Output: 4**↵
↵
Explanation:↵
The four possible subarrays are as follows: ↵
↵
[0 1] 0 1 --> [0,1]↵
↵
0 [1 0] 1 --> [1,0]↵
↵
0 1 [0 1] --> [0,1]↵
↵
[0 1 0 1] --> [0,1,0,1]↵
↵
With the given constraints, expecting solution no worse than O(n)↵
↵
P.s: Maybe the problem can be solved using the sliding window technique. But unable to apply it due to ratio constraint.