Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    Practice problems / Minimum cost to connect all points

    Minimum cost to connect all points

    Mediumgraphminimum spanning treeprim

    Connecting points [x1, y1] and [x2, y2] costs |x1 - x2| + |y1 - y2|. Return the minimum total cost to connect every point so there's a path between any two.

    Example 1

    Input:  points = [[0,0],[2,2],[3,10],[5,2],[7,0]]
    Output: 20

    Example 2

    Input:  points = [[3,12],[-2,5],[-4,1]]
    Output: 18

    Constraints

    • 1 ≤ points.length ≤ 1000
    • -10⁶ ≤ x, y ≤ 10⁶
    • All points are distinct

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

    /**
     * @param {int[][]} points
     * @return {int}
     */
    function minCostConnectPoints(points) {
      
    }
    
    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.