Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding
Ninjas X Naukri.com

Problem of the day

Given a singly linked list of * 'N'* nodes. The objective is to determine the middle node of a singly linked list. However, if the list has an even number of nodes, we return the second middle node.

Detailed explanation

```
5
1 2 3 4 5
```

```
3 4 5
```

```
We can clearly see that there are 5 elements in the linked list therefore the middle node is the node with value '3'.
```

```
6
1 2 3 4 5 6
```

```
4 5 6
```

```
We can clearly see that there are 6 elements in the linked list and the middle nodes are nodes with values 3 and 4 hence we return a second middle node having value '4'.
```

```
1 <= 'N' <= 10^4
0 <= 'data' <= 10^3
Where 'N' is the length of the linked list.
Time Limit: 1 sec
```