One string is a normal string and another string is a shuffled one. Find out whether the given strings are equal or not after shuffling. - Link
large = 256
def compare(string1, string2):
global large
for i in range(large):
if (string1[i] != string2[i]):
return False
return True
def search(X, S):
N1 = len(X)
N2 = len(S)
sumP = [0 for i in range(large)]
sumT = [0 for i in range(large)]
for i in range(N1):
sumP[ord(X[i])] += 1
sumT[ord(S[i])] += 1
for i in range(N1, N2):
if (compare(sumP, sumT)):
return True
countTW[ord(S[i])] += 1
countTW[ord(S[i - N1])] -= 1
if(compare(sumP, sumT)):
return True
return False
S = "BACDGABCDA"
X = "ABCD"
if (search(X, S)):
print("Yes")
else:
print("No")
Comments
Leave a comment