Answer to Question #256403 in Python for rasi

Question #256403

 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

 


1
Expert's answer
2021-10-27T00:26:44-0400
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")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS