Given a binary string str, the task is to find the maximum length of the sub-string of str that has odd parity. A binary string is said be odd parity if it contains odd number of 1s.
Input: str = “1001110”
“001110” is the valid sub-string.
Input: str = “101101”
- Count the number of 1s in the given string and store it in a variable cnt.
- If cnt = 0 then there is no sub-string possible with odd parity so the result will be 0.
- If cnt is odd then the result will be the complete string.
- Now for the case when cnt is even and > 0, the required sub-string will either start at index 0 and end just before the last occurrence of 1 or start just after the first occurrence of 1 and end at the end of the given string.
- Choose the one with the greater length among the two sub-strings in the previous step.
Below is the implementation of the above approach:
- Length of the largest substring which have character with frequency greater than or equal to half of the substring
- Find length of longest subsequence of one string which is substring of another string
- Find if a given string can be represented from a substring by iterating the substring “n” times
- Maximum length substring having all same characters after k changes
- Length of the longest valid substring
- Length of the longest substring with equal 1s and 0s
- Longest Even Length Substring such that Sum of First and Second Half is same
- Length of the longest substring that do not contain any palindrome
- Minimum length substring with exactly K distinct characters
- Length of the longest substring with no consecutive same letters
- Minimum K such that every substring of length atleast K contains a character c
- Length of the longest substring without repeating characters
- Substring with highest frequency length product
- Number of binary strings such that there is no substring of length ≥ 3
- Convert to a string that is repetition of a substring of k length
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.