Description
Description
Editorial
Editorial
Solutions
Solutions
Submissions
Submissions
Medium

You are given a binary string s.

Return the number of with dominant ones.

A string has dominant ones if the number of ones in the string is greater than or equal to the square of the number of zeros in the string.

 

Example 1:

Input: s = "00011"

Output: 5

Explanation:

The substrings with dominant ones are shown in the table below.

ijs[i..j]Number of ZerosNumber of Ones
33101
44101
230111
341102
2401112

Example 2:

Input: s = "101101"

Output: 16

Explanation:

The substrings with non-dominant ones are shown in the table below.

Since there are 21 substrings total and 5 of them have non-dominant ones, it follows that there are 16 substrings with dominant ones.

ijs[i..j]Number of ZerosNumber of Ones
11010
44010
14011022
041011023
150110123

 

Constraints:

  • 1 <= s.length <= 4 * 104
  • s consists only of characters '0' and '1'.
 
Code
Code
Testcase
Testcase
Test Result
Test Result