Using tail reduces complexity from O(N*min(k)^2) to O(N*min(k))