Suppose we have a string s, we have to check whether we can split it into four sub-strings such that each of them are non-empty and unique.
So, if the input is like s = "helloworld", then the output will be True as one of the possible set of sub-strings are ["hel", "lo", "wor", "ld"]
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
def solve(s): if len(s) >= 10: return True for i in range(1, len(s)): for j in range(i + 1, len(s)): for k in range(j + 1, len(s)): sub1 = s[0:i] sub2 = s[i:j - i] sub3 = s[j: k - j] sub4 = s[k: len(s) - k] if sub1 != sub2 and sub1 != sub3 and sub1 != sub4 and sub2 != sub3 and sub2 != sub4 and sub3 != sub4: return True return False s = "helloworld" print (solve(s))
"helloworld"
True