As reported: Walmart SDE intern college hiring, online test on HackerEarth (Mar 2024), coding question 2 (50 points): Unreachable Pairs After Edge Removal — an undirected connected graph, edges are removed one by one, and the task counts the pairs
(u, v)that become unreachable.
The graph has n nodes 0 … n−1 and the list edges (connected at the start; parallel edges possible). removals lists edge indices in the order they are removed (each index at most once). After each removal, return the number of unordered pairs {u, v} that are not connected.
Example 1
n = 4, edges = [[0,1],[1,2],[2,3],[0,2]], removals = [3,1,0]
-> [0, 4, 5]
Removing [0,2] keeps everything connected. Removing [1,2] leaves {0,1} and {2,3}: 4 pairs are cut. Removing [0,1] leaves {0}, {1}, {2,3}: 5 pairs.
Example 2
n = 3, edges = [[0,1],[1,2]], removals = [0,1] -> [2, 3]
Constraints: 2 ≤ n ≤ 10^5; n − 1 ≤ edges.length ≤ 2·10^5; 1 ≤ removals.length ≤ edges.length. Counts can exceed 32 bits.
Code runner format: one JSON value per line: n, edges, then removals. Implement unreachablePairs(n, edges, removals); the harness prints the list of counts.