Can anyone tell we how I can do this in less than n^2