Ask A Question

Subscribe You’re not receiving notifications from this thread.

Is An Anagram

Challenges • Asked 9 months ago by Jake from AlgoDaily

Gravatar Martti Commented on Jul 05, 2019:

Since the previous challenge already mentioned time complexities. It should be mentioned that the sorting solution is Quasilinear O(n log n) and a linear solution exists. If you create a set from both strings O(n+m) and then check that both strings are subsets of each other O(n+m) you can check for anagrams in linear time O(n).

Admittedly JS doesn't allow you to succinctly check set equality, so you'd have to write the loops yourself. It would probably be better just to use the example 3 liner.

Terms and Conditions | Privacy