FastPrepCount Binary Substrings
Problems/Count Binary Substrings

Count Binary Substrings

DocuSign logoDocuSign● EasyFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names a Count Binary Substrings interview question. The function signature, the examples, and the input limits come from an equivalent task we already reviewed. Our version is about 95% the same as the reported question.

Given a binary string s, count the nonempty substrings that have the same number of 0 and 1 characters, where all the 0 characters sit together and all the 1 characters sit together. A substring is a piece of s made of characters that are next to each other.

Count pieces by where they are, so equal text at different places is counted more than once.

Function

countBinarySubstrings(s: String) → int

Examples

Example 1

s = "00110011"return = 6

In order of where they start, the valid pieces are 0011, 01, 1100, 10, 0011, and 01. That is six pieces, so the answer is six.

Example 2

s = "10101"return = 4

Each pair of neighbors, such as the first two characters, is a valid piece. There are four pairs, so that is four pieces. A longer piece like the first four characters switches between the two digits more than once, so it does not count. The answer is four.

Constraints

  • 1 <= s.length <= 100000.
  • Every character of s is 0 or 1.

More DocuSign Onsite Interview questions

  • Two Positions That Add Up to a TargetPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Compress Consecutive Integer RangesONSITE INTERVIEW · Seen Aug 2026
  • JSON Schema Object ValidatorONSITE INTERVIEW · Seen Aug 2026
  • Most Transactions Kept Without Going NegativeONSITE INTERVIEW · Seen May 2025
  • Three-Part Splits With a Light MiddleONSITE INTERVIEW · Seen May 2025
  • Combine Two Sorted Lists Into OneONSITE INTERVIEW · Seen Apr 2022
  • Exact Palindrome CheckPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2022
  • Paired Words That Share a SubstringONSITE INTERVIEW · Seen Apr 2022
  • Reverse the Characters of a TextPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2022
  • Reverse the Order of a Linked ListONSITE INTERVIEW · Seen Feb 2020

Similar questions at other companies

  • Longest Spoken PrefixElevenLabs · ONSITE INTERVIEWElevenLabs interview questions
  • Palindrome Check Ignoring SymbolsWalmart · ONSITE INTERVIEWWalmart interview questions
  • Reverse a String Keeping Dashes in PlaceNykaa · ONSITE INTERVIEWNykaa interview questions
  • Reverse Vowels of a StringGoogle · ONSITE INTERVIEWGoogle interview questions
  • Valid Palindrome After NormalizationKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Minimum Changes for Palindromic BlocksCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
  • Palindrome Match PercentageApple · ONSITE INTERVIEWApple interview questions
  • Reverse A StringNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
  • Validate a Word AbbreviationSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Run-Length String CompressionOracle · ONSITE INTERVIEWOracle interview questions

DocuSign interview experiences

  • DocuSign SWE Intern Interviews: 27 Experiences (Part 2 of 2)
  • DocuSign SWE Intern OA Questions: 53 Experiences (Part 1 of 2)
All DocuSign interview questionsSee DocuSign hiring insights
Saved
class Solution {
    public int countBinarySubstrings(String s) {
        // Write your code here.
    }
}
Checking account…