Google interview question

algorithms, runtime complexity, explaining thought process