Google Interview Question

a memory and complexity coding problem