The error here is not understanding the data being transformed.
You won't get it right either way if you don't /know/ how big n is going to be.
If you can't know, why not? Should you even be coding this at all?
Maybe there should be a rule zero.
0) Understand the data on which your data transformation is going to operate.
The extent you don't is the extent to which the endeavour is doomed.