Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    Practice problems / Remove the nth node from the end

    Remove the nth node from the end

    Mediumlinked listtwo pointers

    Remove the nth node from the end of the list (n = 1 is the last node) and return the head. Try doing it in one pass.

    Example 1

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

    Example 2

    Input:  head = [1], n = 1
    Output: []

    Example 3

    Input:  head = [1,2], n = 1
    Output: [1]

    Constraints

    • 1 ≤ number of nodes ≤ 30
    • 0 ≤ Node.val ≤ 100
    • 1 ≤ n ≤ number of nodes

    Submit checks your solution against 10 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
     * @param {int} n
     * @return {ListNode|null}
     */
    function removeNthFromEnd(head, n) {
      
    }
    
    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.