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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Minimum size substring to be removed to make a given string palindromic
- Minimum cuts required to convert a palindromic string to a different palindromic string
- Minimum removal of subsequences of distinct consecutive characters required to empty a given string
- Sum of indices of Characters removed to obtain an Empty String based on given conditions
- Minimum number of characters to be removed to make a binary string alternate
- Minimum palindromic subarray removals to make array Empty
- Make palindromic string non-palindromic by rearranging its letters
- Minimum characters required to be removed to sort binary string in ascending order
- Number of palindromic subsequences of length k where k <= 3
- Minimum removal of consecutive similar characters required to empty a Binary String
- Longest Palindromic Substring using Palindromic Tree | Set 3
- Minimum and maximum number of digits required to be removed to make a given number divisible by 3
- Minimum Count of Bit flips required to make a Binary String Palindromic
- Minimum characters to be replaced to make a string concatenation of a K-length palindromic string
- Number of subsequences in a given binary string divisible by 2
- Minimum number of elements to be removed so that pairwise consecutive elements are same
- Find the minimum number of elements that should be removed to make an array good
- Minimum number of subsequences required to convert one string to another
- Minimum number of subsequences required to convert one string to another using Greedy Algorithm
- Minimize deletions in a Binary String to remove all subsequences of the form "0101"