Google interview question

time complexity