ByteDance interview question

algo question that uses backtracking.