Pregunta de entrevista de Shop Bonsai

One typical algorithm question and logic problems.