Pregunta de entrevista de Yelp

Asked one algorithm question and solve it with backtracking.