Pregunta de entrevista de Snap

typical leetcode backtracking question with time and space complexity.