Domanda di colloquio di Amazon

find if 2 strings are anagrams

Risposte di colloquio

Anonimo

11 ago 2012

Hash what, lol ? :))) You simply need to alphabetically sort characters in strings and then compare the result.

3

Anonimo

24 set 2012

think about the time complexity. Whats the time complexity of the sorting? NlogN And when using hash mapping, it can be only N. Mapping the string to an alphabet array, the index is the char and the value stores the frequency of the char. Hope it helps.

3

Anonimo

7 apr 2015

Just reverse one string and then compare the result with other string.

Anonimo

29 lug 2012

hash

Anonimo

2 ott 2012

easiest way probably to reduce the characters to ascii, add them all together. If values are equal, they all contain the same characters. O(n)