


This is a visualization of the Circular Linked List, represented by:
1 2 3 4 5 -1

The Circular Linked List before/after deletion may happen to be empty. In that case, only print -1.
All integers in the list are unique.
The first input line contains the integers present in the circular linked list in order.
The second input line contains a single integer 'key', the key to be deleted.
-1 marks the end of the linked list however, the tail of the linked list would be pointing to the head making it circular in nature.
The only output line contains the updated circular linked list post deletion.
0 <= N <= 10 ^ 5
1 <= key <= 10 ^ 5
Where 'N' is the length of the Circular Linked List.
Time limit: 1 sec
The idea is to use a recursive approach to find the given key and then remove that node. The recursive idea is very clear that we will traverse through the circular linked list, and we will check if the value of the node is equal to the given key.
We will define a function deleteNodeHelper(root, key, head) to remove the key in which the head is the starting node of the linked list, and we will send root as the next node of the head node.
Here is complete algorithm: