Given two binary strings s and t. The task is to rearrange the string s in such a way that the occurrence of string t as a sub-string in s is maximum.
Input: s = “101101”, t = “110”
Input: s = “10”, t = “11100”
Input: s = “11000100”, t = “101”
Approach: If we can not make any occurrence of string t in string s then output any permutation of s. Otherwise, start the rearranged string with t. Now we will make the next occurrence of string t in string s as left as possible in order maximize the count of occurrence. To achieve this we will find the largest suffix of string t that matches the prefix of string t
of the same length. It can be found by Prefix Function, Z-Function or Hashes.
Below is the implementation of the above approach:
- Rearrange the string to maximize the number of palindromic substrings
- Find indices of all occurrence of one string in other
- Program to count occurrence of a given character in a string
- Minimize the length of string by removing occurrence of only one character
- Count occurrence of a given character in a string using Stream API in Java
- Rearrange characters in a string such that no two adjacent are same
- Rearrange a string so that all same characters become d distance away
- Generate two output strings depending upon occurrence of character in input string.
- Rearrange a string so that all same characters become atleast d distance away
- Rearrange characters in a string such that no two adjacent are same using hashing
- Check if it is possible to rearrange a binary string with alternate 0s and 1s
- Rearrange a binary string as alternate x and y occurrences
- Rearrange a string in sorted order followed by the integer sum
- Generate two output strings depending upon occurrence of character in input string in Python
- Rearrange the given string such that all prime multiple indexes have same character
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.