• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
July 18, 2024 |6.0K Views

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

  Share   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/