As reported: Goldman Sachs Analyst CoderPad round (2025): people form a directed acyclic graph (one-directional links, no cycles), each person has a unique id; given an id, that person gets a virus — return all the people who will get the virus. Follow-up: the id becomes a list of ids, with minimal code change.
People are connected by directed links edges[i] = [a, b], meaning the virus passes from person a to person b. The links form a directed acyclic graph. The people in sources are infected first.
Return the ids of everyone who ends up infected (including the people in sources), in ascending order.
Example 1
edges = [[1,2],[1,3],[3,4],[5,6]], sources = [1]
-> [1,2,3,4]
Example 2
edges = [[1,2],[1,3],[3,4],[5,6]], sources = [3,5]
-> [3,4,5,6]
Constraints: 0 ≤ edges.length ≤ 10^5; ids are integers in [1, 10^6]; 1 ≤ sources.length ≤ 100; a source id may have no links.
Code runner format: one JSON value per line: edges, then sources. Implement infected(edges, sources); the harness prints the sorted list.