Meta Interview Question

Leetcode medium two questions. backtracking