Hey everyone, and welcome back.
Let's go ahead and try to solve this question over here, which is a very famous coding interview question
called permutations.
Given an array numb's of distinct integers return all possible permutations.
You can return the answer in any order.
So notice over here it's given that the array which is given to us will consist of distinct integers,
and we have to return all the possible permutations.
An example is given over here.
If the array which is given to us is one, two, three, then these are the six possible permutations,
and it's mentioned that we can return the answer in any order.
All right.
So the question is pretty straightforward.
And always remember in coding interview questions do ask any clarifying questions when you are presented
with a problem.
Now a sample question that you could possibly ask at this point is what should be the case?
Or what should happen if numb's is empty?
Should I just return an empty array?
And let's say the interviewer replies that you will not be given an empty array.
It will always have at least one element.
All right, so we have understood the question.
Basically, we will be given an array of distinct integers, and we have to return all the possible
permutations that can be made.
So let's go ahead and write a few test cases.
As we've already seen, if the input array is one, two, three then the output which is expected is
an array which consists of six elements.
And all these elements are arrays in themselves.
So these are the six permutations that are possible for this input array.
Now let's go ahead and write a few more test cases.
What if just one element is given as the input?
If that is the case, then the output will be an array consisting of one element, and this element
itself is going to be an array.
Always the answer is going to be an array of arrays.
And what if there are two elements.
Let's say the input is one comma two.
In this case the output will have two elements.
That's one two and two one.
So the output is going to be an array that consists of these two elements.
So we have understood the question, and we have also come up with a few test cases.
And remember, coming up with test cases helps you to think about the question in a thorough manner.
So it's always a good practice to write out a few test cases before you go ahead and start solving the
question.
In the next video, let's try to think how we can solve this question.