Question bank › Graphs Bfs
Dsa Graphs Bfs Warm-up

City Connection Query

You are given a number of cities and the connections between them. Determine if two cities are connected directly or indirectly through other cities. The input will contain connections in the form of 'city1 city2' and will end with '0'. After that, a set of queries follows where each query is a pair of cities. For each query, print 'Yes' if they are connected and 'No' if they are not. Example Input: a b a c b d 0 a d b c c a Example Output: Yes Yes Yes

Key concepts

graphsbfsconnectivity

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.