Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    Practice problems / Partition a list around a value

    Partition a list around a value

    Mediumlinked listtwo pointers

    Move every node with a value less than x before the nodes with values x or greater, keeping the original order within each group.

    Example 1

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

    Example 2

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

    Constraints

    • 0 ≤ number of nodes ≤ 200
    • -100 ≤ Node.val ≤ 100
    • -200 ≤ x ≤ 200

    Submit checks your solution against 9 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} x
     * @return {ListNode|null}
     */
    function partition(head, x) {
      
    }
    
    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.