1
00:00:00,700 --> 00:00:02,170
Let's do this question.

2
00:00:02,170 --> 00:00:04,720
Given the root of a binary tree.

3
00:00:04,750 --> 00:00:07,840
Imagine yourself standing on the right side of it.

4
00:00:07,840 --> 00:00:11,890
Return the values of the nodes you can see ordered from top to bottom.

5
00:00:11,890 --> 00:00:13,150
So this is the first question.

6
00:00:13,150 --> 00:00:18,460
The second question is given the root of a binary tree, imagine yourself standing on the left side

7
00:00:18,460 --> 00:00:19,000
of it.

8
00:00:19,000 --> 00:00:22,690
Return the values of the nodes you can see ordered from top to bottom.

9
00:00:22,690 --> 00:00:24,310
So this is the same question.

10
00:00:24,310 --> 00:00:29,080
Just in the first case, you're standing on the right side, and in the second case you're standing

11
00:00:29,080 --> 00:00:30,040
on the left side.

12
00:00:30,040 --> 00:00:31,780
So let's see how we can solve this.

13
00:00:31,780 --> 00:00:34,120
And let's first try to understand the question.

14
00:00:34,120 --> 00:00:37,270
Let's say this is the binary tree which is given to us.

15
00:00:37,270 --> 00:00:42,340
And let's say we are standing on the right and we are looking at the binary tree in this direction.

16
00:00:42,340 --> 00:00:44,110
So we can see these nodes.

17
00:00:44,110 --> 00:00:44,410
Right.

18
00:00:44,560 --> 00:00:48,730
We can see four, we can three, we can see three, seven, five and 12.

19
00:00:48,730 --> 00:00:50,920
We cannot see one because it's blocked by this.

20
00:00:50,920 --> 00:00:52,900
Three because these two are in the same level.

21
00:00:52,900 --> 00:00:57,640
Similarly we cannot see two and eight because it is blocked by seven, because all these three are in

22
00:00:57,640 --> 00:00:58,480
the same level.

23
00:00:58,480 --> 00:01:00,430
And then we can see five and 12.

24
00:01:00,430 --> 00:01:03,760
So this is the right side view of this binary tree.

25
00:01:03,760 --> 00:01:10,330
So for question one the output should be an array with these values which is four, three, seven five

26
00:01:10,330 --> 00:01:11,020
and 12.

27
00:01:11,020 --> 00:01:15,400
Now for question two we are looking at this binary tree from the left side.

28
00:01:15,400 --> 00:01:17,260
So that's in this direction.

29
00:01:17,260 --> 00:01:19,690
So the nodes that we can see are these right.

30
00:01:19,690 --> 00:01:22,300
So we can see 4125 and 12.

31
00:01:22,300 --> 00:01:24,700
We cannot see three because it's blocked by one.

32
00:01:24,700 --> 00:01:27,490
We cannot see eight and seven because it's blocked by two.

33
00:01:27,490 --> 00:01:29,110
And we can see five and 12.

34
00:01:29,110 --> 00:01:34,360
So the output array for question number two should be 4125 and 12.

35
00:01:34,360 --> 00:01:35,710
So this is the question.

36
00:01:36,190 --> 00:01:40,390
Now let's proceed and take a look at a few test cases.

37
00:01:40,390 --> 00:01:47,050
Now let's say the binary tree which is given to us is having just one node.

38
00:01:47,050 --> 00:01:52,630
So in this case even if we look from the right or from the left, we will just see that particular node.

39
00:01:52,630 --> 00:01:55,690
So the output should be just an array with that particular value.

40
00:01:55,690 --> 00:01:56,020
Right.

41
00:01:56,020 --> 00:02:01,930
And if we are given a null null binary tree where the root itself is null in this case we will just

42
00:02:01,930 --> 00:02:03,160
return an empty array.

43
00:02:03,160 --> 00:02:08,350
And remember in the interview you have to come up with test cases together with your interviewer to

44
00:02:08,350 --> 00:02:11,020
ensure that both of you are on the same page.

45
00:02:11,020 --> 00:02:15,460
And then we have already discussed this case where this is the binary tree which is given to us.

46
00:02:15,460 --> 00:02:19,420
Now, if you look from the right, you can see four, three, seven, five and 12.

47
00:02:19,420 --> 00:02:20,410
So this is the output.

48
00:02:20,410 --> 00:02:24,460
And if you look from the left you can see four one, two, five and 12.

49
00:02:24,460 --> 00:02:25,720
So this is the output.

50
00:02:25,720 --> 00:02:26,950
So this is the question.

51
00:02:26,950 --> 00:02:29,140
And we have looked at a few test cases.

52
00:02:29,140 --> 00:02:33,670
Now in the next video let's try to think how we can solve this question.
