Pergunta de entrevista da empresa The Home Depot

Given two strings of equal length, write a function that determines if they are anagrams (that is, if one string can be rearranged to form the other string)

Respostas da entrevista

Sigiloso

18 de mai. de 2021

Using JavaScript, I created a JSON structure that counts how many times each letter appears in the first string. Then I compared it to the second string; if a letter appeared that was already in the key-value map, I decremented the value of that letter. If all of the values are 0 at the end, and no new letters have appeared, it's an anagram.

1

Sigiloso

19 de abr. de 2022

I think another solution could be to sort each string and compare.