1
00:00:00,330 --> 00:00:01,320
Welcome back, everyone.

2
00:00:01,980 --> 00:00:07,530
So when you come up with your test case for these interface design questions, what will happen is that

3
00:00:07,530 --> 00:00:13,440
you're going to be expected to call your interface and its methods in a sequence of ways that built

4
00:00:13,440 --> 00:00:16,380
out the tree that I showed you in the previous example.

5
00:00:16,890 --> 00:00:22,260
Generally speaking, your interviewer may or may not walk through the problem as extensively as I did.

6
00:00:22,530 --> 00:00:28,380
But as you start thinking about test cases or conversing with your interviewer, a general picture of

7
00:00:28,380 --> 00:00:30,920
what we went through should emerge here.

8
00:00:30,930 --> 00:00:36,630
What you'll see will happen is that with our general test case, what we've done is initialized the

9
00:00:36,630 --> 00:00:38,410
monarchy with Jake as the king.

10
00:00:38,790 --> 00:00:43,680
So what we're doing is calling the methods in the same order that we went through in order to build

11
00:00:43,680 --> 00:00:44,740
out such a tree.

12
00:00:45,090 --> 00:00:47,370
So we need to call the birth of Katherine to Jake.

13
00:00:47,680 --> 00:00:53,250
And here you might change up the order in which these different calls happen, but it should not deviate

14
00:00:53,250 --> 00:00:54,810
from how this tree looks.

15
00:00:54,810 --> 00:01:00,900
In the end, the only thing to consider is the order in which children get born to their parent.

16
00:01:01,230 --> 00:01:07,620
What this means is that because Seline is the third child of Jake, you cannot call the birth of Seline

17
00:01:07,830 --> 00:01:14,100
before you call the birth of Tom, because if you do, then Saleen gets born before Tom does.

18
00:01:14,310 --> 00:01:19,410
This might be one of those cases where, as you're thinking about this test case, that's something

19
00:01:19,410 --> 00:01:24,390
that pops to your mind about the way that the children are ordered, because the succession of this

20
00:01:24,390 --> 00:01:27,150
example does matter by birth order.

21
00:01:27,270 --> 00:01:29,130
So that's an important thing you need to notice.

22
00:01:29,470 --> 00:01:34,740
So let's say, for example, Arthur Katherine gets born to Jake, Jane gets born to Katherine, then

23
00:01:34,740 --> 00:01:39,390
let's say father gets born to Jane and then Tom gets born to Jake here.

24
00:01:39,390 --> 00:01:43,170
It doesn't matter when Tom is born, as long as it's after Katherine.

25
00:01:43,180 --> 00:01:46,590
Katherine can have all of her children and you can call all of these arguments.

26
00:01:46,890 --> 00:01:50,310
However, you must call Tom before sailin.

27
00:01:50,340 --> 00:01:54,540
That's the real only order that matters as far as the children birth order goes.

28
00:01:55,050 --> 00:01:55,890
Let's say afterwards.

29
00:01:55,890 --> 00:02:01,380
Then Celine gets born to Jake and let's say Marc then gets born to Katherine and then Peter gets born

30
00:02:01,380 --> 00:02:02,010
to Celine.

31
00:02:02,430 --> 00:02:08,090
Even in this order, this is still the resulting tree for our best case test case example.

32
00:02:08,370 --> 00:02:13,710
So when you think about how you're designing the order of the calls of this monarchy, because at this

33
00:02:13,710 --> 00:02:19,740
point we know what these methods will do, we have to think about how it constrains to the give an example

34
00:02:19,740 --> 00:02:21,720
of what exactly we're trying to build is.

35
00:02:21,990 --> 00:02:25,980
And here this should be very clearly defined to you by your interviewer.

36
00:02:26,040 --> 00:02:28,650
When they told you about the monarchy family tree.

37
00:02:28,950 --> 00:02:33,150
You might want to discuss this as well as your writing this out, because at this point, when you're

38
00:02:33,150 --> 00:02:38,490
figuring out these methods and when to call them to form this tree, these might be the types of examples

39
00:02:38,490 --> 00:02:39,690
that are jumped to your head.

40
00:02:40,320 --> 00:02:43,560
So moving on from here, let's say we call, then get order of succession.

41
00:02:43,890 --> 00:02:50,670
Clearly, the order of succession goes Jake, then Catherine and then Jane and then Fera, because these

42
00:02:50,670 --> 00:02:54,750
are all of the first borns, first born children and subsequent first born children.

43
00:02:55,110 --> 00:03:02,130
And then after that, it goes Mark for Katherine and then it goes Tom and then finally Saleen and Peter.

44
00:03:02,550 --> 00:03:05,400
So this is the same order of succession we saw earlier.

45
00:03:05,880 --> 00:03:09,480
Let's say once again, we kill off Jake and we kill off Jane.

46
00:03:09,990 --> 00:03:12,990
What then happens if we scratch out these names?

47
00:03:14,590 --> 00:03:20,440
To represent their deaths, as that will see the new order of succession goes Katherine and then Farah,

48
00:03:20,830 --> 00:03:26,260
as you can see, and then it's Mark and then Tom and then Celine and Peter, which is also what you

49
00:03:26,260 --> 00:03:28,100
see in the remainder of the array.

50
00:03:28,540 --> 00:03:34,270
So this is going to be the order of calls that will come from the interface that we're expected to design

51
00:03:34,270 --> 00:03:35,670
as our test case.

52
00:03:35,950 --> 00:03:40,750
So with interface design questions, oftentimes what's going to happen is that they want to test that.

53
00:03:40,750 --> 00:03:47,620
The order of your sequencing of what the logic is intended to achieve with your interface is valid once

54
00:03:47,620 --> 00:03:48,900
you've designed the interface.

55
00:03:49,150 --> 00:03:54,250
So these are the different ways that you want to think about what kind of constraints you need to capture

56
00:03:54,250 --> 00:03:57,110
in the logic of the interface that you're designing.

57
00:03:57,550 --> 00:04:03,100
So now that we understand what it is that we're building here, I want you to try and see if you can

58
00:04:03,100 --> 00:04:07,900
figure out some of the insights so that you can try and solve this question yourself.

59
00:04:08,500 --> 00:04:11,430
Some hints that might help you before you dive in.

60
00:04:11,590 --> 00:04:16,570
You can pause the video here and try and figure out yourself or you can listen to me talk and then try

61
00:04:16,570 --> 00:04:19,620
it yourself, because in the next video, we're going to solve it all together.

62
00:04:20,080 --> 00:04:25,840
But what I want you to notice is that this is indeed a tree structure and the order of succession is

63
00:04:25,840 --> 00:04:28,710
probably the most challenging part here.

64
00:04:28,720 --> 00:04:32,320
What I want you to think about is the order in which these elements appear.

65
00:04:32,560 --> 00:04:38,530
And when you think about this tree, it's not a binary tree, but it is a binary tree, meaning that

66
00:04:38,560 --> 00:04:43,870
there are still these different tree nodes, but they might have any number of branches.

67
00:04:44,200 --> 00:04:50,770
So here you can still utilize the exact same traversal order, breadth versus depth research that we

68
00:04:50,770 --> 00:04:56,740
know with trees, because as we know with enteric trees, these are still trees at the end of the day,

69
00:04:56,860 --> 00:05:02,230
which means that our breadth of research and our depth research and even our subsequent order of the

70
00:05:02,230 --> 00:05:07,040
traversal, whether it's preorder in order or post order, these are all things that can help you.

71
00:05:07,330 --> 00:05:12,970
So I want you to think about this question in the context of what it's like to build out an energy tree

72
00:05:13,360 --> 00:05:15,780
and then perform one of these search algorithms.

73
00:05:15,790 --> 00:05:22,300
And when you do think about that order traversal, if it even helps you, so it's kind of a tree problem

74
00:05:22,300 --> 00:05:24,790
that's wrapped up inside of this interface.

75
00:05:25,030 --> 00:05:29,350
But this is where I mentioned that these different data structures that you already know could help

76
00:05:29,350 --> 00:05:30,970
you solve these problems.

77
00:05:31,090 --> 00:05:35,460
In fact, these problems are probably grounded in these data structures that you already know.

78
00:05:35,890 --> 00:05:38,560
So here, I want you to try and solve this question yourself.

79
00:05:38,800 --> 00:05:44,920
Think about that interface design, those three methods, birth, death and the order of succession

80
00:05:44,920 --> 00:05:46,930
and how it all ties together.

81
00:05:47,320 --> 00:05:50,110
I'm going to solve it with a JavaScript class in the next video.

82
00:05:50,260 --> 00:05:53,980
You might have to do it in your own native language implementation, whichever language you choose to

83
00:05:53,980 --> 00:05:54,280
do.

84
00:05:54,730 --> 00:05:57,070
And in the next video, let's do it together.

