question check whether two strings are anagram of each other write a function to check whether two given strings are anagram of each other or not an anagram of a string is another string that contains same characters only the order of characters can be different for example abcd and dabc are anagram of each other source a very common interview question asked in companies like amazon goldman sachs and nagarro time complexity the goal is to complete this question in on this solution is optimized by using bit manipulation if we start at a value of 0 and xor all the characters of both strings we should return an end value of 0 if they are anagrams because there would be an even occurrence of all characters in the anagram space complexity the space complexity of this approach is o1 function to check whether two strings are anagrams of each other if two strings have different size we return false as they cannot be anagrams of each other variable to store the xor value code to test the function function to check whether two strings are anagrams of each other if two strings have different size we return false as they cannot be anagrams of each other variable to store the xor value code to test the function
def are_anagrams(string1, string2): 
      
    
    if (len(string1) != len(string2)): 
        return False
    
    xor_value = 0
    for i in range(len(string1)):
        xor_value = xor_value ^ ord(string1[i]) 
        xor_value = xor_value ^ ord(string2[i])

    if(xor_value==0):
    	return True
    else:
    	return False


string1 = "thestringsareanagrams"
string2 = "arethestringsanagrams"
if(are_anagrams(string1, string2)): 
    print("The two strings are anagram of each other")
else: 
    print("The two strings are not anagram of each other")