As reported: Goldman Sachs Associate Superday, panel DSA round 1 with two VPs (GBM, 2025): given a list of cities and a boolean API
isDirectConnected(c1, c2), implementisConnected(c1, c2)— graph traversal with a visited set, with a follow-up about the connection being bidirectional.
Direct road connections between cities are given as connections[i] = [a, b]; a connection works in both directions. Two cities are connected if you can travel from one to the other through any number of direct connections; a city is always connected to itself.
Answer each query [c1, c2] in queries with true or false.
Example 1
connections = [["A","B"],["B","C"],["D","E"]]
queries = [["A","C"],["A","D"],["E","D"]]
-> [true,false,true]
Constraints: 0 ≤ connections.length ≤ 10^4; 1 ≤ queries.length ≤ 10^4; city names are non-empty strings; a queried city may have no connections.
Code runner format: one JSON value per line: connections, then queries. Implement isConnected(connections, queries); the harness prints the list of booleans.