All practice tasks

Coding (Algo)

Critical Service Links

Depth first search · Hard

A service mesh must identify individual undirected links whose loss would disconnect part of the current network.

Return every bridge edge by its original input index.

Input

Call

  • Implement solve(input) and return its result. Do not print from solve.

Input object

{ n:integer, links:[u:integer,v:integer][] }

Input rules

  • Parallel links and self-links are allowed.

What each field means

  • n — number of nodes, identified by 0 through n - 1.
  • links — undirected [u, v] edges. Each edge is identified by its zero-based position in this array.

Output

Return value and rules

  • Return indexes of edges whose individual removal increases the number of connected components.
  • Return indexes in increasing order. Parallel edges remain distinct edges.
  • Check all components even if the original graph is already disconnected.

Constraints

  • 0 <= n <= 2000; 0 <= links.length <= 20000
  • All endpoints valid. Input may already be disconnected; evaluate each connected component.

Examples

Example 1

{
  "links": [
    [
      0,
      1
    ],
    [
      1,
      2
    ],
    [
      2,
      0
    ],
    [
      2,
      3
    ]
  ],
  "n": 4
}

Returns

[
  3
]

Example 2

{
  "links": [],
  "n": 0
}

Returns

[]

Required complexity

O(n + m) time and O(n + m) space

What this task practices

Critical Service Links is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as hard difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.