ByteDance Interview Question

Permutation question from leetcode (BackTracking)