Remove Max Number of Edges to Keep Graph Fully Traversable
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
An undirected graph has n nodes labeled 1 to n. Each edge edges[i] = [type_i, u_i, v_i] has one of three types:
- Type 1: only Alice can use it.
- Type 2: only Bob can use it.
- Type 3: both Alice and Bob can use it.
The graph is **fully traversable** by a person if, using only the edges that person may use, every node can reach every other node.
Return the **maximum number of edges you can remove** so that the remaining graph is still fully traversable by both Alice and Bob. If it is not fully traversable by both even with all edges, return -1.
Examples
Constraints
- `2 <= n <= 10^5`
- `1 <= edges.length <= min(10^5, 3 * n * (n - 1) / 2)`
- `edges[i][0]` is 1, 2, or 3
- `1 <= u_i < v_i <= n`
- All tuples `(type_i, u_i, v_i)` are distinct
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.