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

