Given binary string S of size N and a number K. The task is to find the Longest sub string of 0’s in the string which is formed by repeating given string K times.
Input : S = “100001” , K = 3
Output : 4
After repeating given string 3 time, string becomes 100001100001100001.
The longest substring of 0’s is 4
Input : S = “010001000”, K = 4
Output : 4
- If K is one, then find the longest substring of 0’s in a string using a simple loops
- If K is greater than one, then add a given string to the end of the string. Then string becomes S+S and length will be 2*N and find the longest substring of 0’s in a string using a simple loops
- If the longest substring is 2*N then, our answer will be K*N
- Otherwise it will be the our required answer
Below is the implementation of the above approach:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Check if any permutation of string is a K times repeated string
- String which when repeated exactly K times gives a permutation of S
- Number of subsequences as "ab" in a string repeated K times
- String obtained by reversing and complementing a Binary string K times
- Build a DFA to accept a binary string containing "01" i times and "1" 2j times
- Longest subsequence of the form 0*1*0* in a binary string
- Longest sub-sequence of a binary string divisible by 3
- Check if a string can be repeated to make another string
- Length of longest consecutive ones by at most one swap in a Binary String
- Count of times second string can be formed from the characters of first string
- Find the longest sub-string which is prefix, suffix and also present inside the string
- Longest palindromic string formed by concatenation of prefix and suffix of a string
- Find the longest sub-string which is prefix, suffix and also present inside the string | Set 2
- Find length of longest subsequence of one string which is substring of another string
- Periodic Binary String With Minimum Period and a Given Binary String as Subsequence.
- Longest string in an array which matches with prefix of the given string
- Print the longest prefix of the given string which is also the suffix of the same string
- Longest string which is prefix string of at least two strings
- Queries for characters in a repeated string
- Find the first repeated word in a string
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.