AT&T interview question

Permutation leetcode Hard type question