Pergunta de entrevista da empresa Clearwater Analytics (CWAN)

Given a string, how would you write a method to tell if it's an anagram?

Resposta da entrevista

Sigiloso

5 de jan. de 2017

1) Check if string1 and string2 are same length, if so continue, otherwise not an anagram 2) Check if string1 and string2 are already equal, if so they are anagram, otherwise continue 3) Assign A-Z to 26 unique prime numbers (i.e. A = 2, B = 3, C = 5, D = 7, E = 11, etc) 4) Loop through string1, using prime number values from step 3, multiply each letter and save product 5) Loop through string2, using prime number values from step 3, multiply each letter and save product 6) compare products from steps 4/5, if equal they are anagrams, else they are not anagrams, Proof through theory of arithmetic.