What is the time complexity of this code? Can this be made faster?