Pregunta de entrevista de MetTel

One Simple Algorithm question and One Simple Database query