Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5761 |

@blackshadows | 5715 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4944 |

@saiujwal13083 | 4506 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3516 |

@sushant_a | 3459 |

@verma_ji | 3341 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@aroranayan999 | 1115 |

@bt8816103042 | 739 |

@thealchemist627 | 456 |

@dalwainazism125 | 453 |

@akashkale117 | 453 |

@shivanandp12345678910 | 453 |

@codeantik | 448 |

@SherlockHolmes3 | 447 |

@SHOAIBVIJAPURE | 430 |

@shalinibhataniya1097 | 408 |

@ShamaKhan1 | 392 |

Complete Leaderboard |

Given a binary string S. The task is to count the 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”.

**Example 1:**

**Input:
**N = 4**
**S = 1111
**Output: **6**
Explanation: **There are 6 substrings from
the given string. They are 11, 11, 11,
111, 111, 1111.

**Example 2:**

**Input:
**N = 5**
**S = 01101
**Output: **3**
Explanation: **There 3 substrings from the
given string. They are 11, 101, 1101.

**Your Task:**

The task is to complete the function **binarySubstring() **which takes the length of binary string **n** and a binary string **a** as input parameter and counts the number of substrings starting and ending with 1 and returns the count.

**Expected Time Complexity: **O(N).

**Expected Auxiliary Space: **O(1).

**Constraints:**

1 ≤ |S| ≤ 10^{4}

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Binary String

...