Interview Question

Software Design Engineer In Test Interview Seattle, WA

find if 2 strings are anagrams

Answer

Interview Answer

5 Answers

0

hash

Interview Candidate on Jul 28, 2012
3

Hash what, lol ? :)))

You simply need to alphabetically sort characters in strings and then compare the result.

Jack on Aug 11, 2012
2

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.

xli on Sep 23, 2012
0

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)

B on Oct 2, 2012
0

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

San on Apr 7, 2015

Add Answers or Comments

To comment on this, Sign In or Sign Up.