Two iterations to create two lists to compare their length + one iteration to create map + one iteration for all. Sounds like `O(3N* logN)` vs just `O(logN)` for avg case.  Yes, it's verbose, but dramatically ineffective and this is not something tricky to keep it such.