Suppose we have two strings s and t and r, we have to check whether r = s | t or r = t + s where | denotes concatenation.
So, if the input is like s = "world" t = "hello" r = "helloworld", then the output will be True as "helloworld" (r) = "hello" (t) | "world" (s).
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
def solve(s, t, r): if len(r) != len(s) + len(t): return False if r.startswith(s): if r.endswith(t): return True if r.startswith(t): if r.endswith(s): return True return False s = "world" t = "hello" r = "helloworld" print(solve(s, t, r))
"world", "hello", "helloworld"