Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    Practice problems / Insert an interval

    Insert an interval

    Mediumarrayintervals

    intervals holds non-overlapping [start, end] intervals sorted by start. Insert extra, merge any overlaps, and return the sorted result. Touching intervals ([1,2] and [2,3]) merge.

    Example 1

    Input:  intervals = [[1,3],[6,9]], extra = [2,5]
    Output: [[1,5],[6,9]]

    Example 2

    Input:  intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], extra = [4,8]
    Output: [[1,2],[3,10],[12,16]]

    Constraints

    • 0 ≤ intervals.length ≤ 10⁴
    • 0 ≤ start ≤ end ≤ 10⁵

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

    /**
     * @param {int[][]} intervals
     * @param {int[]} extra
     * @return {int[][]}
     */
    function insertInterval(intervals, extra) {
      
    }
    
    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.