1
00:00:00,110 --> 00:00:02,150
Hey everyone, and welcome back.

2
00:00:02,180 --> 00:00:08,930
Let's go ahead and try to solve this question over here, which is a very famous coding interview question

3
00:00:08,930 --> 00:00:10,280
called permutations.

4
00:00:10,580 --> 00:00:17,240
Given an array numb's of distinct integers return all possible permutations.

5
00:00:17,240 --> 00:00:20,120
You can return the answer in any order.

6
00:00:20,120 --> 00:00:26,810
So notice over here it's given that the array which is given to us will consist of distinct integers,

7
00:00:26,810 --> 00:00:30,470
and we have to return all the possible permutations.

8
00:00:30,530 --> 00:00:32,450
An example is given over here.

9
00:00:32,450 --> 00:00:39,260
If the array which is given to us is one, two, three, then these are the six possible permutations,

10
00:00:39,260 --> 00:00:43,310
and it's mentioned that we can return the answer in any order.

11
00:00:43,460 --> 00:00:44,090
All right.

12
00:00:44,090 --> 00:00:46,370
So the question is pretty straightforward.

13
00:00:46,370 --> 00:00:53,570
And always remember in coding interview questions do ask any clarifying questions when you are presented

14
00:00:53,570 --> 00:00:54,560
with a problem.

15
00:00:54,560 --> 00:01:00,380
Now a sample question that you could possibly ask at this point is what should be the case?

16
00:01:00,500 --> 00:01:03,650
Or what should happen if numb's is empty?

17
00:01:03,650 --> 00:01:05,990
Should I just return an empty array?

18
00:01:05,990 --> 00:01:11,630
And let's say the interviewer replies that you will not be given an empty array.

19
00:01:11,630 --> 00:01:14,240
It will always have at least one element.

20
00:01:14,570 --> 00:01:16,880
All right, so we have understood the question.

21
00:01:16,880 --> 00:01:24,200
Basically, we will be given an array of distinct integers, and we have to return all the possible

22
00:01:24,200 --> 00:01:25,880
permutations that can be made.

23
00:01:25,880 --> 00:01:29,300
So let's go ahead and write a few test cases.

24
00:01:29,780 --> 00:01:37,790
As we've already seen, if the input array is one, two, three then the output which is expected is

25
00:01:37,790 --> 00:01:40,790
an array which consists of six elements.

26
00:01:40,790 --> 00:01:43,850
And all these elements are arrays in themselves.

27
00:01:43,850 --> 00:01:49,070
So these are the six permutations that are possible for this input array.

28
00:01:49,220 --> 00:01:52,040
Now let's go ahead and write a few more test cases.

29
00:01:52,040 --> 00:01:55,670
What if just one element is given as the input?

30
00:01:55,670 --> 00:02:03,500
If that is the case, then the output will be an array consisting of one element, and this element

31
00:02:03,500 --> 00:02:05,630
itself is going to be an array.

32
00:02:05,630 --> 00:02:08,900
Always the answer is going to be an array of arrays.

33
00:02:09,410 --> 00:02:11,270
And what if there are two elements.

34
00:02:11,270 --> 00:02:14,030
Let's say the input is one comma two.

35
00:02:14,030 --> 00:02:17,480
In this case the output will have two elements.

36
00:02:17,480 --> 00:02:20,330
That's one two and two one.

37
00:02:20,960 --> 00:02:26,090
So the output is going to be an array that consists of these two elements.

38
00:02:27,210 --> 00:02:32,760
So we have understood the question, and we have also come up with a few test cases.

39
00:02:32,760 --> 00:02:41,130
And remember, coming up with test cases helps you to think about the question in a thorough manner.

40
00:02:41,130 --> 00:02:48,300
So it's always a good practice to write out a few test cases before you go ahead and start solving the

41
00:02:48,300 --> 00:02:48,930
question.

42
00:02:50,130 --> 00:02:55,320
In the next video, let's try to think how we can solve this question.
