Given two special characters, the first character can be represented by one bit which is 0 and the second character can be represented by two bits either 10 or 11. Now given a string represented by several bits. The task is to return the number of characters it represents. Note that the given string is always valid.
Input: str = “11100”
“11”, “10” and “0” are the required characters.
Input: str = “100”
Approach: The approach to solve the problem is that if the current character is 0 then it represents a single character of 1 bit but if the current character is 1 then the next bit after it has to be included in the character consisting of two bits as there is no single bit characters starting with 1.
Below is the implementation of the above approach:
- Count of ungrouped characters after dividing a string into K groups of distinct characters
- Count of times second string can be formed from the characters of first string
- Binary string with given frequencies of sums of consecutive pairs of characters
- Count number of substrings of a string consisting of same characters
- Check whether count of distinct characters in a string is Prime or not
- Count pairs of characters in a string whose ASCII value difference is K
- Count characters in a string whose ASCII values are prime
- Minimum number of characters to be removed to make a binary string alternate
- Count the nodes of a tree whose weighted string does not contain any duplicate characters
- Count ways to partition a string such that both parts have equal distinct characters
- Program to count vowels, consonant, digits and special characters in string.
- Count of substrings of a binary string containing K ones
- Count of cyclic permutations having XOR with other binary string as 0
- Count of non-overlapping sub-strings "101" and "010" in the given binary string
- Count of operations to make a binary string"ab" free
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : AnkitRai01