1
00:00:00,890 --> 00:00:01,940
Hi everyone!

2
00:00:01,940 --> 00:00:04,730
Let's now solve these two questions.

3
00:00:04,730 --> 00:00:07,220
Create a doubly linked list class.

4
00:00:07,220 --> 00:00:13,250
Write instance methods for this class to be able to remove all the nodes in the doubly linked list,

5
00:00:13,250 --> 00:00:15,950
which have their value equal to the given value.

6
00:00:15,950 --> 00:00:17,360
So that's the first question.

7
00:00:17,360 --> 00:00:20,870
And the second question is insert a node at a desired position.

8
00:00:20,870 --> 00:00:26,180
Again, it's an instance method which can insert a node at a desired position.

9
00:00:26,180 --> 00:00:27,770
Node and position are given.

10
00:00:27,770 --> 00:00:29,960
The linked list is zero indexed.

11
00:00:29,960 --> 00:00:34,850
If given node is a node existing in the linked list, shift it to the desired position.

12
00:00:34,850 --> 00:00:35,210
All right.

13
00:00:35,210 --> 00:00:36,260
So this is the question.

14
00:00:36,260 --> 00:00:37,940
Again we will do the first question.

15
00:00:37,940 --> 00:00:40,430
First we will write test cases.

16
00:00:40,430 --> 00:00:44,990
We will write the method discuss the method write the code walk through the code.

17
00:00:44,990 --> 00:00:47,030
And then we will come to the second question.

18
00:00:47,030 --> 00:00:48,530
All right let's get started.

19
00:00:48,710 --> 00:00:51,710
Over here it says we have to write an instance method.

20
00:00:51,710 --> 00:00:53,660
And a value will be given to us.

21
00:00:53,660 --> 00:00:59,480
And we have to remove all the nodes from the doubly linked list which have the value equal to the value

22
00:00:59,480 --> 00:01:00,020
given.

23
00:01:00,020 --> 00:01:05,390
Now this is very much similar to the, uh, methods that we have written in the previous question.

24
00:01:05,390 --> 00:01:10,760
Again, these two questions are similar and we will be making use of those functions over here.

25
00:01:10,760 --> 00:01:14,450
Now let's proceed and write a few test cases again.

26
00:01:14,450 --> 00:01:20,030
Remember in the interview, always feel free to ask clarifying questions if you have any doubts.

27
00:01:20,030 --> 00:01:22,100
Now let's write a few test cases.

28
00:01:22,100 --> 00:01:27,950
Let's say this is the doubly linked list which is given to us, and let's say the value is given as

29
00:01:27,950 --> 00:01:33,170
two, and we are asked to delete all the nodes, or we are asked to remove all the nodes in the doubly

30
00:01:33,170 --> 00:01:35,690
linked list, which have their value equal to two.

31
00:01:35,720 --> 00:01:37,970
So what would be the expected output?

32
00:01:38,180 --> 00:01:42,260
We would need to remove these three for these four nodes.

33
00:01:42,260 --> 00:01:42,440
Right.

34
00:01:42,440 --> 00:01:43,850
There are four nodes with value two.

35
00:01:43,880 --> 00:01:45,830
So we would have to remove these four.

36
00:01:45,830 --> 00:01:49,820
And the doubly linked list become will become this over here.

37
00:01:49,820 --> 00:01:50,240
Right.

38
00:01:50,240 --> 00:01:52,400
We'll just have these two nodes remaining.

39
00:01:52,400 --> 00:01:54,860
And then they will be connected to each other.

40
00:01:54,860 --> 00:01:56,810
And then over here we'll have null and null.

41
00:01:56,810 --> 00:01:58,730
So this is the output that we need.

42
00:01:58,730 --> 00:02:01,400
So this is pretty straightforward right now.

43
00:02:01,400 --> 00:02:02,480
What could we do.

44
00:02:02,480 --> 00:02:06,740
Let's discuss in the next video how we can solve this question.
