This has O(n^2) complexity. If the purpose is to merge counters. You should trim keys before adding them into the counter. And then merge another counter in-place.