My issue
Traceback (most recent call last):
File “/mnt/sol.py”, line 68, in
T = int(input().strip()) # Number of test cases
^^^^^^^
EOFError: EOF when reading a line
My code
class Node:
def __init__(self, data=None):
self.data = data
self.next = None
def duplicateRemoval(head):
if head is None:
return head
current = head
while current and current.next:
if current.data == current.next.data:
current.next = current.next.next
else:
current = current.next
return head
# Example usage:
def printList(head):
current = head
while current:
print(current.data, end=" ")
current = current.next
print()
# Sample input
T = int(input())
for _ in range(T):
N = int(input())
elements = list(map(int, input().split()))
# Creating linked list
head = Node(elements[0])
current = head
for num in elements[1:]:
current.next = Node(num)
current = current.next
# Removing duplicates
head = duplicateRemoval(head)
# Printing modified list
printList(head)
Learning course: Placement preparation for Product companies
Problem Link: Duplicate Removal Practice Problem in Placement preparation for Product companies - CodeChef