Pregunta de entrevista de Pinterest

Leetcode hard question on backtracking.