Pregunta de entrevista de Bloomberg

Was asked a stack based Algo and a backtracking question.