Given a string consisting only of 1’s and 0’s. In one flip we can change any continuous sequence of this string. Find this minimum number of flips so the string consist of same characters only.
Input : 00011110001110 Output : 2 We need to convert 1's sequence so string consist of all 0's. Input : 010101100011 Output : 4
We need to find the min flips in string so all characters are equal. All we have to find numbers of sequence which consisting of 0’s or 1’s only. Then number of flips required will be half of this number as we can change all 0’s or all 1’s.
Time Complexity: O(n)
This article is contributed by nuclode. 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 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 flips required to generate continuous substrings of 0’s and 1’s
- Minimum Group Flips to Make Binary Array Elements Same
- Minimum letters to be removed to make all occurrences of a given letter continuous
- Find Bit whose minimum sequence flips makes all bits same
- Minimum flips to make all 1s in left and 0s in right | Set 2
- Minimize flips required to make all shortest paths from top-left to bottom-right of a binary matrix equal to S
- Minimum flips to make all 1s in right and 0s in left
- Minimum Count of Bit flips required to make a Binary String Palindromic
- Minimum number of flips with rotation to make binary string alternating
- Number of flips to make binary string alternate | Set 1
- Minimum characters to be replaced to make frequency of all characters same
- Minimize replacements by previous or next alphabet required to make all characters of a string the same
- Minimum flips required in a binary string such that all K-size substring contains 1
- Minimum flips required to form given binary string where every flip changes all bits to its right as well
- Minimum non-adjacent pair flips required to remove all 0s from a Binary String
- Minimum flips required to keep all 1s together in a Binary string
- Modify the string by swapping continuous vowels or consonants
- Wrap every continuous instance of given word with some given string
- Minimize characters to be changed to make the left and right rotation of a string same
- Count minimum right flips to set all values in an array