Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    Practice problems / Redundant connection

    Redundant connection

    Mediumgraphunion find

    A tree with n nodes labelled 1 to n got one extra edge, creating a cycle. edges lists the edges in order. Return an edge whose removal leaves a tree; if several qualify, return the last one in edges.

    Example 1

    Input:  edges = [[1,2],[1,3],[2,3]]
    Output: [2,3]

    Example 2

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

    Constraints

    • 3 ≤ n == edges.length ≤ 1000
    • The graph is a tree plus one edge

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

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