Google Online Coding Round 2021 Problem !!!

Revision en1, by cf_rk, 2021-08-06 22:12:35

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!

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English cf_rk 2021-08-06 22:12:35 530 Initial revision (published)