Shortest Walk That Visits Every Server in a Small Cluster Graph
Last updated: November 29, 2026
Quick Overview
A maintenance bot must visit every one of up to 12 servers connected by an undirected, unweighted network graph. It can start and end anywhere and revisit nodes and edges. Return the length of the shortest such walk.
Meta
November 29, 20260
0
0 solved
A maintenance bot must visit every one of up to 12 servers connected by an undirected, unweighted network graph. It can start and end anywhere and revisit nodes and edges. Return the length of the shortest such walk.
A Meta onsite question combining BFS with bitmask state. The interviewer looks for the (node, visited-set) state space, multi-source BFS from every start, and a clear reason why BFS gives shortest walks here.
What the Interviewer Expects
- Model state as (current node, visited mask)
- Run multi-source BFS starting from every (i, 1 << i)
- Explain why BFS is optimal on unweighted state graphs
- Stop at the first state with the full mask
- State O(2^n * n^2) complexity
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- What if edges have weights?
- Return the actual walk, not just its length.
- How would you approximate this for 1,000 servers?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: adjacency list graph for n <= 12 nodes, connected, undirected. Output: minimum number of edges in a walk visiting all nodes. Revisiting is allowed, so this is not a Hamiltonian path question;...
High-Level Design
The position alone is not enough state, because whether we are done depends on which nodes were seen. Use state (node, mask), where mask is the set of visited nodes. Moving along an edge to v costs ...