Counting Binary Substrings (Backend)

Problem Overview

  • Count substrings in a binary string where 0s and 1s form consecutive groups and the counts of 0s and 1s are equal.
  • Input: binary string s (length 5 to 5×10^5, only '0' and '1'); Output: integer count of valid substrings.
  • Domain: backend string processing and binary data validation in streams.
  • This coding interview problem is an interview question from Canva interviews (Backend).
  • Complete counting(s) to return the total number of matching substrings.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: