Given a string, the task is to check if we can split it into 4 string such that each string is non-empty and different from each other.
Input : str = "geeksforgeeks" Output : Yes "geeks", "for", "gee", "ks" are four distinct strings that can form from given string. Input : str = "aaabb" Output : No
Observe if the length of the string is greater than or equal to 10, then every time can split into four parts. Suppose, the length is of 10, then string of length 1, 2, 3, 4 can be made.
For string having length less than 10, we can use brute force i.e iterate through the all possible ways of splitting the string and check each one.
If length is more than 10 return true Else (If length is less than 10) Use Brute Force method to check if we can break it in four distinct strings.
Below is the implementation of above idea.
This article is contributed by Anuj Chauhan. 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.
- Check if a string can be split into two strings with same number of K-frequent characters
- Check if a string can be split into even length palindromic substrings
- Check if a string can be split into substrings starting with N followed by N characters
- Meta Strings (Check if two strings can become same after a swap in one string)
- Check whether given string can be generated after concatenating given strings
- Split the string into minimum parts such that each part is in the another string
- Split the given string into Primes : Digit DP
- Split the given string into Odds: Digit DP
- Remove minimum characters from string to split it into three substrings under given constraints
- Split a given string into substrings of length K with equal sum of ASCII values
- Find all possible ways to Split the given string into Primes
- Count of ways to split given string into two non-empty palindromes
- Distinct strings such that they contains given strings as sub-sequences
- Check whether two strings can be made equal by reversing substring of equal length from both strings
- Ways to split string such that each partition starts with distinct character
- Check if given string can be formed by two other strings or their permutations
- Check if K palindromic strings can be formed from a given string
- Check if a Palindromic String can be formed by concatenating Substrings of two given Strings
- Check if characters of a given string can be used to form any N equal strings
- Minimum number of substrings the given string can be splitted into that satisfy the given conditions