Skip to content
Discussion options

You must be logged in to vote

We need to count the number of substrings in a binary string where the number of ones is greater than or equal to the square of the number of zeros. The challenge is to efficiently compute this without checking every possible substring explicitly, which would be computationally expensive for large strings.

Approach:

  1. Problem Analysis: The problem requires checking all possible substrings of the given binary string to determine if they meet the condition where the number of ones is at least the square of the number of zeros. Directly checking all substrings would result in an O(n^2) solution, which is inefficient for large strings (n up to 40,000).

  2. Key Insight: For any substring to sati…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Nov 15, 2025
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants