Exodus interview question

How I would solve a specific algorithm