Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    Practice problems / Merge two sorted lists

    Merge two sorted lists

    Easylinked listtwo pointersrecursion

    a and b are linked lists sorted in ascending order. Merge them into one sorted list made of the same nodes and return its head.

    Example 1

    Input:  a = [1,2,4], b = [1,3,4]
    Output: [1,1,2,3,4,4]

    Example 2

    Input:  a = [], b = [0]
    Output: [0]

    Constraints

    • 0 ≤ nodes in each list ≤ 50
    • -100 ≤ Node.val ≤ 100
    • Both lists are sorted in non-decreasing order

    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} a
     * @param {ListNode|null} b
     * @return {ListNode|null}
     */
    function mergeTwoLists(a, b) {
      
    }
    
    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.