NEOFACTO interview question

First step to solve task