Transform string to adjacency list
Last updated: November 14, 2025
Quick Overview
Given a string representation of a graph where each node is connected by commas, transform this string into an adjacency list. The output should be a dictionary where each key is a node and its value is a list of connected nodes. For example, the input "A,B,C;B,A;C,B" should produce an adjacency list like {"A": ["B", "C"], "B": ["A", "C"], "C": ["B"]}.
Anduril
November 14, 202538
12
3,301 solved
Given a string representation of a graph where each node is connected by commas, transform this string into an adjacency list. The output should be a dictionary where each key is a node and its value is a list of connected nodes. For example, the input "A,B,C;B,A;C,B" should produce an adjacency list like {"A": ["B", "C"], "B": ["A", "C"], "C": ["B"]}.
This coding problem is frequently asked during Technical Screen at Anduril. The interviewer is testing your ability to translate a problem into clean, working code while discussing time and space complexity. Anduril expects candidates to write production-quality code, not just solve the puzzle.
What the Interviewer Expects
- Identify the correct data structure and algorithm for the problem
- Write clean, bug-free code with proper variable naming
- Analyze time and space complexity correctly
- Handle basic edge cases (empty input, single element)
- Communicate your thought process while coding
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 happens if the input contains duplicates?
- What is the worst-case input for your solution?
- What if the input doesn't fit in memory?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Problem Analysis
The problem requires us to convert a string representation of a graph into an adjacency list format, which is a common way to represent graphs using dictionaries in Python. The graph is represented as...
Approach
- Initialize an empty dictionary: This will hold our adjacency list.
- Split the input string by semicolons to separate each connection.
- Iterate through each connection: For each conn...