Saturday Questions | Python DSA Practice

Saturday Questions: Linked Lists in Python

This edition of Saturday Questions is focused on a classic Data Structures and Algorithms topic: linked lists.

Linked lists teach students how data can be connected through references instead of being stored in one continuous block like an array or list. The main idea is simple but powerful: each node stores data and points to the next node.

Advertisement

What you will learn

  • Node and next reference
  • Linked list traversal
  • Insertion at beginning and end
  • Deletion from a linked list
  • Searching, reversing, and merging

Difficulty path

  • Very simple: create and print nodes
  • Simple: insert, search, and count
  • Medium: delete and reverse
  • Interview level: middle node, merge, and cycle detection

Main idea

A linked list is not about storing values only. It is about connecting values carefully.

The basic linked list pattern

Most linked list programs begin with a small node class and a reference to the first node, usually called head.

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

head = Node(10)
head.next = Node(20)
head.next.next = Node(30)

current = head
while current is not None:
    print(current.data)
    current = current.next
The most important habit is to protect the links. Before changing next, think carefully about which node may become unreachable.

Questions included in this edition

  1. Create a node and print its data
  2. Create a linked list from a Python list
  3. Print all elements of a linked list
  4. Count the number of nodes in a linked list
  5. Search for a value in a linked list
  6. Insert a node at the beginning
  7. Insert a node at the end
  8. Delete the first occurrence of a value
  9. Reverse a linked list
  10. Find the middle node of a linked list
  11. Merge two sorted linked lists
  12. Detect a cycle in a linked list

Practice area

Use the embedded practice viewer below. Read each question carefully, try the starter code, then compare your approach with the explanation.

Saturday Questions Viewer Open full screen

How to attempt the challenge

  • First, draw the nodes and arrows on paper.
  • Keep track of the head node carefully.
  • Use a current variable for traversal.
  • Before deleting or reversing, store the next node safely.
  • Test empty lists, single-node lists, and multi-node lists.

Why linked lists matter in hiring

Linked list questions are common in coding interviews because they test whether the student understands references, memory-style thinking, and careful step-by-step logic. A linked list problem often looks small, but one careless pointer change can break the entire structure.

Students who become comfortable with linked lists usually become stronger at trees, graphs, recursion, and many other connected data structures.