Suppose you are given an Array : a[] = { 0 , 0 , 1 , 0 , 0} . size of array can be large upto 2e5. **** You have to count all the subarrays in which a particular element x occurs more than length(subarray) /2 times
for example if x = 0 :
subarrays are :
{0} index = 1
{0} index = 2
{0} index = 4
{0} index = 5
{0,0} index 1 --> 3
{0,0} index 4 -->5
{0,0,1}
{0,1,0}
{1,0,0}
{0,0,1,0}
{0,1,0,0}
{0,0,1,0,0}
ans = 12.
Any idea !