I think that you're still missing the lookup into the hash, which isn't a constant time operation and can't be factored out because the OP doesn't have it. Since the best you can do with such a lookup is O(log(N)), IMHO the complexity in your case is at least O(N * log(N)).