Middle of Linked List
Practice this coding question on Coding Gurukul.
Problem statement
A support queue is represented by a singly linked list. A supervisor begins an audit at the middle request and then examines every remaining request through the end of the queue. Your task Return the middle node of the linked list and print the list starting at that node. If the list has two middle nodes, choose the second. Build a singly linked list from the input values and perform the operation on its nodes. Important details Use slow and fast pointers in O(n) time and O(1) auxiliary space. A one-node list returns that node. Output the suffix beginning at the selected node, not just its value and not the first half. Worked example For 1 -> 2 -> 3 -> 4, the middle candidates are 2 and 3. Choose 3, so the printed suffix is 3 4.
Input format
The first line contains n. The next line contains n space-separated integers; for n = 0 this line may be empty.
Output format
Print the resulting values in order, separated by spaces. Print EMPTY if there are no values.
Constraints
1 <= n <= 100; 1 <= values <= 100.
Sample input
4 1 2 3 4
Sample output
3 4
Sign in to run or submit a solution in C++, Java or Python.