Google DeepMind interview question

Medium difficulty array coding question