Remitly interview question

Similar to a leetcode hard problem utilizing backtracking.