Given a binary string, count minimum number of subsequences to be removed to make it an empty string.
Input: str = "10001" Output: 1 Since the whole string is palindrome, we need only one removal. Input: str = "10001001" Output: 2 We can remove the middle 1 as first removal, after first removal string becomes 1000001 which is a palindrome.
Expected time complexity : O(n)
The problem is simple and can be solved easily using below two facts.
1) If given string is palindrome, we need only one removal.
2) Else we need two removals. Note that every binary string has all 1’s as a subsequence and all 0’s as another subsequence. We can remove any of the two subsequences to get a unary string. A unary string is always palindrome.
- Extend the above solution to count minimum number of subsequences to be removed to make it an empty string.
- What is the maximum count for ternary strings
This problem and solution are contributed by Hardik Gulati. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- Minimum number of characters to be removed to make a binary string alternate
- Number of subsequences in a given binary string divisible by 2
- Minimum cuts required to convert a palindromic string to a different palindromic string
- Number of palindromic subsequences of length k where k <= 3
- Find the minimum number of elements that should be removed to make an array good
- Minimum number of operations required to sum to binary string S
- Minimum number of swaps to make two binary string equal
- Minimum number of operations on a binary string such that it gives 10^A as remainder when divided by 10^B
- Minimum number of replacements to make the binary string alternating | Set 2
- Number of K length subsequences with minimum sum
- Given a number as a string, find the number of contiguous subsequences which recursively add up to 9 | Set 2
- Given a number as a string, find the number of contiguous subsequences which recursively add up to 9
- Count minimum number of subsets (or subsequences) with consecutive numbers
- Number of subsequences in a string divisible by n
- Number of subsequences as "ab" in a string repeated K times