cf_rk's blog

By cf_rk, history, 5 years ago, In English

You are given a binary string s (consisting of 0's and 1's). Count the number of substrings with count of 1's > count of 0's.

For eg. Input: 1010 Output: 3 Explanation: Possible substring with count of 1's > count of 0's are : {1} , {101} , {1}.

What I did? I converted all 0's to -1. Then the problem reduces to Count number of subarrays with positive sum. Then I used fenwick tree for it and it passed.

Is there any other approach for this. Thanks in advance!

Full text and comments »

  • Vote: I like it
  • -21
  • Vote: I do not like it