Pregunta de entrevista de Bank BTPN

Simple algorithm puzzle that should be coded live