Now we should benchmark @FortranFan’s and @Arjen’s solutions. The complexity seems O(n^2)
for both, but I would expect @FortranFan’s to be a lost faster, as there are no allocations/reallocations.
I think that must be why the Rosetta page has some solutions using a hash table, I guess then the complexity is only O(n)
.