Welcome back.
Let's now go ahead and write the pseudocode for the approach that we have discussed.
And again let's make use of the backtracking blueprint that we previously discussed.
So we have the blueprint over here.
This is the pseudocode that we have discussed for the permutations question.
Now let's see how we have to slightly modify this to get to the approach that we have discussed over
here.
So the change that we need to do is that for each value of I, we need to check whether the value of
J was already encountered or not.
So for example, remember over here initially j is equal to zero.
The value is one and then j is equal to one.
Again the value is one.
So these two values are the same.
And because we were inserting values to the hash table or dictionary, we are able to identify that
this is a repetition.
And we skip this.
And we proceed to the next branch.
So for this we would need a hash table or a dictionary.
So at this point let's say we declare it so hash is an empty object.
And then before we do these three steps which is equivalent to going deeper on the recursion tree,
we check whether numb's at j is in the hash table or not.
Now, if it is not in the hash table first we will insert it to the hash table, and then we will proceed
with these three steps over here.
So this is how we can solve this.
So notice over here in the permutations question we did not have an is valid over here.
We did not have any is valid function.
There was nothing to check over here because every choice was valid.
But in this question we have a criteria to check whether the choice is valid or not, which is whether
numb's at j is in the hash table or not.
Now we proceed with choose and recursively calling the function and reverting the choice only if numb's
at j is not in the hash table.
So notice over here we have incorporated this as well in this approach.