Challenges • Asked 9 months ago by Jake from AlgoDaily
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.