Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    Practice problems / Middle of a linked list

    Middle of a linked list

    Easylinked listtwo pointersfast and slow pointers

    Return the middle node of the list (with everything after it). If there are two middle nodes, return the second one.

    Example 1

    Input:  head = [1,2,3,4,5]
    Output: [3,4,5]

    The middle is 3.

    Example 2

    Input:  head = [1,2,3,4,5,6]
    Output: [4,5,6]

    Two middles (3 and 4), so return 4.

    Constraints

    • 1 ≤ number of nodes ≤ 100
    • 1 ≤ Node.val ≤ 100

    Submit checks your solution against 8 tests, including hidden ones.

    // Provided by the judge: keep these definitions
    class ListNode {
      constructor(val = 0, next = null) {
        this.val = val
        this.next = next
      }
    }
    
    /**
     * @param {ListNode|null} head
     * @return {ListNode|null}
     */
    function middleNode(head) {
      
    }
    
    Sign in to run
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.