Citadel interview question

Leetcode hard question related to backtracking