n
is 1, return a string containing all digits from 0 to k-1
as each digit itself is a password.seen
to keep track of visited combinations.result
to store the sequence that will unlock the safe.n-1
zeros.k-1
and check if the new combination has been seen.seen
and recursively call DFS with the new node.result
.result
list into a string and append the starting node to it to form the final password.