Google interview question

Technical coding question with decent difficulty