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 substrings of a given Binary string with all characters same
- Count of binary strings of length N having equal count of 0's and 1's and count of 1's ≥ count of 0's in each prefix substring
- String with k distinct characters and no same characters adjacent
- Periodic Binary String With Minimum Period and a Given Binary String as Subsequence.
- Min flips of continuous characters to make all characters same in a string
- Permutation of a string with maximum number of characters greater than its adjacent characters
- Rearrange the characters of the string such that no two adjacent characters are consecutive English alphabets
- Minimum cost to remove the spaces between characters of a String by rearranging the characters
- Binary string with given frequencies of sums of consecutive pairs of characters
- Strings formed from given characters without any consecutive repeating characters
- Longest substring with atmost K characters from the given set of characters
- Count of times second string can be formed from the characters of first string
- Count characters to be shifted from the start or end of a string to obtain another string
- Count of triplets from the given string with non-equidistant characters
- Print all positions of a given string having count of smaller characters equal on both sides
- Lexicographically smallest string formed by appending a character from the first K characters of a given string
- Program to count vowels, consonant, digits and special characters in string.
- Minimum number of characters to be removed to make a binary string alternate
- Minimum characters required to be removed to sort binary string in ascending order
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