Pregunta de entrevista de Verisk

They asked me to program a simple algorithm.