Skip to content

Practice Minimum Time for K Connected Components

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3608
LeetCode Problem

Minimum Time for K Connected Components

Problem Statement

You are given an integer n and an undirected graph with n nodes labeled from 0 to n - 1. This is represented by a 2D array edges, where edges[i] = [ui, vi, timei] indicates an undirected edge between nodes ui and vi that can be removed at timei. You are also given an integer k. Initially, the graph may be connected or disconnected. Your task is to find the minimum time t such that after removing all edges with time <= t, the graph contains at least k connected components. Return the minimum time t. A connected component is a subgraph of a graph in which there exists a path between any two vertices, and no vertex of the subgraph shares an edge with a vertex outside of the subgraph.

Source: Minimum Time for K Connected Components on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 2, edges = [[0,1,3]], k = 2
Output
3

# Example 2

Input
n = 3, edges = [[0,1,2],[1,2,4]], k = 3
Output
4

# Example 3

Input
n = 3, edges = [[0,2,5]], k = 2
Output
0

Constraints

1 <= n <= 10^5
0 <= edges.length <= 10^5
edges[i] = [ui, vi, timei]
0 <= ui, vi < n
ui != vi
1 <= timei <= 10^9
1 <= k <= n
There are no duplicate edges.

Related LeetCode Problems

Practice more problems similar to Minimum Time for K Connected Components.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.