how to divide strings

Kevin has a string S consisting of N lowercase English letters.

Kevin wants to split it into 4 pairwise different non-empty parts. For example, string “happynewyear” can be splitted into “happy”, “new”, “ye” and “ar”. He can’t delete any characters or change the order of the characters.

Help Kevin and find if there exist at least one possible spliting.

Input format:

The first line of input will contain an integer T, denoting the number of test cases. Each of the next T lines contains a string S.

Output format:

For every test case output “YES” if it is possible to split the string and “NO” otherwise.

Constraints:

1 ≤ T ≤ 100
1 ≤ N ≤ 1000
N ≤ 20 in test data worth 40% of all points
Sample Input(Plaintext Link)
2
ababca
aaabb
Sample Output(Plaintext Link)
YES
NO

dont answer this question its a question from ongoing contest in hackerearth

1 Like

If the length of the string is less than 10, bruteforce over all possible ways of splitting the string.

Otherwise the answer is YES (split the string into four parts of lengths 1, 2, 3, length - 6).

Refer this if you need help with the bruteforce !

1 Like

string

Here is a c program to split a string. We can use the same algorithm to solve this c program also.

Since problem statement is not comprehensible, yet, I make an attempt:

  • If string has to be split in 4 different non-empty parts, then N (string length) must be >= 4 because only being so will make string to split in 4 non-empty parts. So output in “NO” if strlen(str)<4.