1
00:00:00,910 --> 00:00:03,430
Hi everyone, let's do this question.

2
00:00:03,430 --> 00:00:09,460
Given an array, rotate the array to the right by k steps where k is non-negative.

3
00:00:09,460 --> 00:00:10,570
So that's the question.

4
00:00:10,570 --> 00:00:12,310
Now over here we have an example.

5
00:00:12,310 --> 00:00:15,790
Let's say the array which is given to us is 1234 over here.

6
00:00:15,790 --> 00:00:20,770
And if k is equal to one then we have to do one rotation to the right right.

7
00:00:20,770 --> 00:00:23,680
So that will give us 4123.

8
00:00:23,680 --> 00:00:27,760
So you can see that this four over here actually came was rotated to the right.

9
00:00:27,760 --> 00:00:29,920
And because there's nothing over here it came over here.

10
00:00:29,920 --> 00:00:30,070
Right.

11
00:00:30,070 --> 00:00:31,990
So we have 4123.

12
00:00:31,990 --> 00:00:37,390
Now if you do one more rotation that is if k is equal to two then we have after one rotation we have

13
00:00:37,390 --> 00:00:38,620
4123.

14
00:00:38,620 --> 00:00:40,360
And then this three comes over here right.

15
00:00:40,360 --> 00:00:43,420
So this comes over here and we get 341 and two.

16
00:00:43,420 --> 00:00:45,820
So that is what we call right rotations.

17
00:00:45,820 --> 00:00:47,950
So this is the question which we have over here.

18
00:00:47,950 --> 00:00:53,650
Now remember in the interview when you get this question always feel free to ask clarifying questions

19
00:00:53,650 --> 00:00:58,600
so that you thoroughly understand the question and you and the interviewer are on the same page.

20
00:00:58,600 --> 00:01:04,210
So for example, a sample question that you could ask over here is what happens if an empty array is

21
00:01:04,210 --> 00:01:04,660
passed.

22
00:01:04,660 --> 00:01:09,520
So in this case let's say the interviewer replies return an empty array in this case.

23
00:01:09,520 --> 00:01:10,030
All right.

24
00:01:10,060 --> 00:01:14,110
Now another question is if k is equal to zero no rotation is to happen.

25
00:01:14,110 --> 00:01:14,830
Is that correct.

26
00:01:14,830 --> 00:01:17,020
And then let's say the interviewer replies yes.

27
00:01:17,020 --> 00:01:19,570
So you have got a good understanding of the question.

28
00:01:19,570 --> 00:01:22,960
Now let's go ahead and write a few test cases.

29
00:01:22,960 --> 00:01:28,120
Now remember in the interview you can always ask the interviewer, is it okay if we come up with a few

30
00:01:28,120 --> 00:01:29,200
test cases together.

31
00:01:29,200 --> 00:01:32,890
So this will ensure that you are on the same page with the interviewer.

32
00:01:32,890 --> 00:01:35,530
Now let's go ahead and make a few test cases over here.

33
00:01:35,530 --> 00:01:41,110
If the given array is one comma two, and if k is equal to one, then we're just doing one rotation

34
00:01:41,110 --> 00:01:41,290
right.

35
00:01:41,290 --> 00:01:45,400
So this two comes over here and we get two comma one as the output.

36
00:01:45,880 --> 00:01:51,880
Now in this case if k is equal to two we do one more rotation and we get back to one comma two.

37
00:01:51,910 --> 00:01:52,480
All right.

38
00:01:52,510 --> 00:01:56,800
Now let's say the given array is 1234 and k is equal to three.

39
00:01:56,800 --> 00:01:57,070
Right.

40
00:01:57,070 --> 00:01:59,920
So in this case what will happen after one rotation.

41
00:01:59,920 --> 00:02:02,440
We will have 412 and three.

42
00:02:02,440 --> 00:02:05,710
After the next rotation we will have 341 and two.

43
00:02:05,710 --> 00:02:09,520
And after the third rotation we will have 234 and one.

44
00:02:09,520 --> 00:02:10,900
So this would be the case.

45
00:02:10,900 --> 00:02:15,400
Now in this same case if k is equal to zero then we wouldn't do any rotation.

46
00:02:15,400 --> 00:02:18,220
And the array is still one, two, three and four.

47
00:02:18,220 --> 00:02:19,540
So that's clear.

48
00:02:19,540 --> 00:02:25,090
And if an empty array is given and let's say k is equal to two, we just return the empty array.

49
00:02:25,090 --> 00:02:27,640
So we have got a good understanding of the question.

50
00:02:27,640 --> 00:02:30,280
And we have written our test cases in the next video.

51
00:02:30,280 --> 00:02:32,470
Let's think through how we can solve this.

52
00:02:32,470 --> 00:02:37,090
And let's also look at the complexity of analysis of the solutions that we come up with.
