Google interview question

a memory and complexity coding problem