DEV Community

Discussion on: Are these lists equal?

Collapse
 
jiangh profile image
Hong Jiang

You could build a map with list 1, and then iterate over list 2 to compare each element with its count in the map. The asymptotic complexity is the same, but the code would be more concise and efficient (2 loops instead of 3).

Collapse
 
caroso1222 profile image
Carlos Roso

That's right. That's the kind of response I was expecting from this post. My O(n) solution is clear enough to lay a foundation for non-asymptotic optimizations like yours or that of the first comment. Thanks for contributing!