Middle of the Linked List
We want to find the middle node of a singly linked list. If there are two middle nodes, we will return the second one. We’ll use the “tortoise and the hare” approach, also known as Floyd’s cyclefinding algorithm.
 Initialize Two Pointers: We will use two pointers,
slow
andfast
.slow
will move one step at a time, whilefast
will move two steps at a time.  Move Pointers: We’ll move the pointers until
fast
reaches the end or the node before the end of the list.  Return the Middle Node: The
slow
pointer will be at the middle node when thefast
pointer reaches the end.
Here is the code:


Example
 Input:
head = [1,2,3,4,5,6]
 Output:
[4,5,6]
 Explanation: Since the list has two middle nodes with values 3 and 4, we return the second one, which is the node with value 4.
Insights
 Time Complexity: The time complexity is (O(n)), where (n) is the number of nodes in the linked list.
 Space Complexity: The space complexity is (O(1)), as we only use a constant amount of extra space.
 Two Pointer Technique: This approach elegantly finds the middle of the list by using two pointers at different speeds.
Bruteforce Approach Iterate through the entire linked list We can use stack to keep track of all the elements We keep track of the current linked list When we reach the end of the linked list (we encounter nil) Pop the elements of the stack
Slow and Fast Pointers
 When either the fast is null or fast.next is null
Terminating in the while loop The one element case provides the condition

