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 email@example.com. 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.
- Return maximum occurring character in an input string
- Print all the duplicates in the input string
- Remove characters from the first string which are present in the second string
- Remove duplicates from a given string
- A Program to check if strings are rotations of each other or not
- Print reverse of a string using recursion
- Write a program to print all permutations of a given string
- Divide a string in N equal parts
- Given a string, find its first non-repeating character
- Write a program to reverse an array or string
- Check for balanced parentheses in an expression
- Reverse words in a given string
- Find the smallest window in a string containing all characters of another string
- Check whether two strings are anagram of each other
- Print all interleavings of given two strings