Help in this subarray count problem !

Revision en3, by atlasworld, 2019-02-03 16:33:55

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 !

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English atlasworld 2019-02-03 16:33:55 3 Tiny change: 'subarray) times** \' -> 'subarray) /2 times** \'
en2 English atlasworld 2019-02-03 15:04:24 22
en1 English atlasworld 2019-02-03 15:03:49 506 Initial revision (published)