Cognizant Coding Question – Solved

8 Live
A substring is a group of contiguous characters in a string. For instance, all substrings of abc are [a, b, c, ab, bc, abc]. Given a binary representation of a number, determine the total number of substrings present that match the following conditions: 1. The 0s and 1s are grouped consecutively (e.g., 01, 10, 0011, 1100, 000111, etc.). 2. The number of 0s in the substring is equal to the number of 1s in the substring. Example: s = 001101 The 4 substrings matching the two conditions include [0011, 01, 10, 01]. Note that 01 appears twice, from indices 1-2 and 4-5. There are other substrings, e.g., 001 and 011 that match the first condition but not the second. Function Description: Complete the function `counting` in the editor below. counting has the following parameter(s): string s: a string representation of a binary integer

Asked in: Cognizant

Image of the Question

Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| Given an n x m grid, where rows are numbered from 7 to n and columns from 1 to … |
| There are 'N' coders standing in a line, where i denotes the ith position of a … |
| A birthday party was attended by N number of kids, and each kid was given a uni… |
| Given a matrix of size m * n, where m denotes the number of rows (starting with… |
| A traveler is traveling from the city of Zeta to Omega. He starts with X amount… |
| As an operations engineer at Amazon, you are responsible for organizing the dis… |