If you’re new to linked lists, this is a great exercise for learning about them. Given a pointer to the head node of a linked list, print its elements in order, one element per line. If the head pointer is null (indicating the list is empty), don’t print anything.

Input Format

The first line of input contains n, the number of elements in the linked list.

The next n lines contain one element each, which are the elements of the linked list.

Explanation

This is a classic Linked List Node realization below

"""Linked List Realization"""

	class SinglyLinkedListNode:
	    def __init__(self, node_data):
	        self.data = node_data
	        self.next = None

The current exercise is the easiest exercise about Linked List. As you understand from the theoretical part — Linked List Node has a reference on the next element in the next variable. The last node in a list has null in the next variable. So it is a way to check if the current node is a last in List.

#linked-lists #data-structures #hackerrank #problem-solving #python

Print the Elements of a Linked List. HackerRank Exercise
1.55 GEEK