I think you may be overestimating the cost of iterating through the list, especially since it will be unavoidably iterated when it's converted to a map, but it's easy to memoize so I've done so.