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 times second string can be formed from the characters of first string
- 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 number of substrings of a string consisting of same characters
- Count characters in a string whose ASCII values are prime
- Count the nodes of a tree whose weighted string does not contain any duplicate characters
- Minimum number of characters to be removed to make a binary string alternate
- Program to count vowels, consonant, digits and special characters in string.
- Count of substrings of a binary string containing K ones
- Count of non-overlapping sub-strings "101" and "010" in the given binary string
- Count of cyclic permutations having XOR with other binary string as 0
- Given a binary string, count number of substrings that start and end with 1.
- Count of operations to make a binary string"ab" free
- 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
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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