DFS based O(N^2) solution w comments
Complexity\n- Time complexity:\nO(n^2)\n\n- Space complexity:\nO(n)\n\n# Code\n\nclass Solution {\n\n    public int[] findRedundantConnection(int[][] edges) {\n
# Complexity\n- Time complexity:\nO(n^2)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution {\n\n    public int[] findRedundantConnection(int[][] edges) {\n\n        int n = edges.length;\n\n       ArrayList<ArrayList<Integer>> graph = new ArrayList<>();\n\n        for (int i = 0; i < n; i++) {\n            graph.add(new ArrayList<>());\n        }\n\n        for (int[] edge : edges) {\n            int u = edge[0] - 1;\n            int v = edge[1] - 1;\n\n            boolean[] visited = new boolean[n];   //reinitializing the `visited` array before we start exploring again\n/*\nChecking if there is already a path between the two nodes before adding an edge, this way we can identify the additional edge that needs to be removed.\n*/\n            if (dfs(graph, u, v, visited)) {\n                return edge;\n            }\n\n            graph.get(u).add(v);            //otherwise add to the graph\n            graph.get(v).add(u);\n        }\n        \n        return new int[0];          // returning empty list\n    }\n\n    private boolean dfs(ArrayList<ArrayList<Integer>>  graph, int u, int v, boolean[] visited) {\n\n        if (u == v) {               // if src(u) reaches dest(v), then stop thr DFS\n            return true;\n        }\n\n        visited[u] = true;\n\n        for (int next : graph.get(u)) {\n            if (!visited[next]) {\n                if (dfs(graph, next, v, visited)) {\n                    return true;\n                }\n            }\n        }\n        return false;\n    }\n}\n\n\n```
['Depth-First Search', 'Java']