Practice
Resources
Contests
Online IDE
New
Free Mock
Scaler
Practice
Improve your coding skills with our resources
Contests
Compete in popular contests with top coders
Scaler
Explore Offerings by SCALER

Linked Lists

Go to Problems

Level 1

Jump to Level 2

Level 2

Jump to Level 3

Level 3

Jump to Level 4

Level 4

Jump to Level 5

Level 5

Jump to Level 6

Level 6

Jump to Level 7

Level 7

Jump to Level 8

Level 8

Be a Code Ninja!

Linked List Implementation

Each node in a list consists of at least two parts:

    1. Data
    2. Pointer to the next node

In C/C++, we can represent a node of Linked List using structures or classes.
In Java and Python, Linked List can be represented as a class and a Node as a separate class. The LinkedList class contains a reference of Node class type. 

 

An example of a linked list node with an integer data.
// A linked list node
struct ListNode
{
  int val;
  struct ListNode *next;
};
// Linked list class
class ListNode
{
    // head of list
    Node head;
 
    // Node class
    class Node
    {
        int val;
        Node next;
          
        // Constructor to create a new node
        Node(int v) {
           val = v;
        }
    }
}
# Node class
class Node:
    # Function to initialize the node object
    def __init__(self, v):
        self.val = v  # Assign value
        self.next = None  # Initialize next as null
  
# Linked List class
class ListNode:
    # Function to initialize the Linked List
    def __init__(self): 
        self.head = None

Walkthrough Example :

INTERSECTLIST REVLISTSAMPLE

Serious about Learning Programming ?

Learn this and a lot more with Scaler Academy's industry vetted curriculum which covers Data Structures & Algorithms in depth.

Linked Lists Problems

List sort
Problem Score Companies Time Status
Sort Binary Linked List 200 33:16
Partition List 275
49:36
Insertion Sort List 300
49:25
Sort List 350 59:47
Pointer move
Problem Score Companies Time Status
K reverse linked list 200 60:30
Even Reverse 200 44:39
Swap List Nodes in pairs 350 33:34
Rotate List 350 33:58
List trick
Problem Score Companies Time Status
Kth Node From Middle 200 29:46
Reverse Alternate K Nodes 300 52:25
Reverse Link List II 450 57:24
Reorder List 600 57:10
List math
Problem Score Companies Time Status
Add Two Numbers as Lists 250 43:07
List Cycle 600 39:15
Free Mock Assessment
Fill up the details for personalised experience.
All fields are mandatory
Current Employer *
Enter company name *
Graduation Year *
Select an option *
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
Phone Number *
OTP will be sent to this number for verification
+91 *
+91
Change Number
Phone Number *
OTP will be sent to this number for verification
+91 *
+91
Change Number
Graduation Year *
Graduation Year *
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
*Enter the expected year of graduation if you're student
Current Employer *
Company Name *
Please verify your phone number
Edit
Resend OTP
By clicking on Start Test, I agree to be contacted by Scaler in the future.
Already have an account? Log in
Free Mock Assessment
Instructions from Interviewbit
Start Test