Pregunta de entrevista de Samsung Electronics

Something to do with backtracking and optimization