July 18, 2024 |6.1K Views

    Count number of substrings that start and end with 1 in a Binary String

      Share  1 Like
    Description
    Discussion

    Given a binary string, count number of substrings that start and end with 1. For example, if the input string is “00100101”, then there are three substrings “1001”, “100101” and “101”.


    A Simple Solution is to run two loops. Outer loops picks every 1 as starting point and inner loop searches for ending 1 and increments count whenever it finds 1.

     

    Count number of substrings that start and end with 1 in a Binary String: https://www.geeksforgeeks.org/given-binary-string-count-number-substrings-start-end-1/