1022. Split a Circular Linked List
Your task is to divide a circular linked list of positive integers into two circular linked lists, with the first list containing the first half of the nodes (exactly ceil(list.length / 2) nodes) in the same order that they appeared in the list, and the second list containing the remaining nodes in the same order that they appeared in the list.
Provide a two-length array response with a circular linked list representing the first half as its first element and a circular linked list representing the second half as its second.
The only distinction between a circular linked list and a regular linked list is that the first node is the node that comes after the last node.
Example 1:
Input : nums = [1, 2, 3, 4]
Output : [ [1, 2], [3, 4] ]
Explanation :
The original linked list has 4 nodes, so the first half would consist of first 2 nodes [1, 2] and second 2 elements will be part of second half [3, 4].
Example 2:
Input : nums = [1, 2, 3]
Output : [ [1, 2], [3] ]
Explanation :
The original linked list has 3 nodes, so the first half would consist of first 2 nodes as ceil(3/2) = 2, [1, 2] and the rest nodes will be part of second half [3].
Now Your Turn!
Pick the correct output for the given inputInput : nums = [1, 2, 3,4,5]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- The number of nodes in list is in the range [2, 105]
- 0 <= Node.val <= 109
- LastNode.next = FirstNode where LastNode is the last node of the list and FirstNode is the first one