Write a function which, given two ASCII strings, determines if they are anagrams. Then, give algorithmic and space complexity.
Anonimo
Initial ideas included sorting the string, and checking character by character. After some probing by the interviewer, discussed how hash tables may make the problem simpler: Using a subroutine which takes a string and converts to a length 128 array, with each subscript representing the count of that ASCII character in the string. Then, in the main procedure, we can just compare the arrays returned by passing each string. In this, we see our space complexity is O(n) (since we have to store two strings of length n, plus two arrays of length 128) and algorithmically is also O(n) (since we must parse two strings of length n, then compare two arrays of length 128).