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
Coding & Algorithms
Software Engineer
Anduril
November 14, 2025
Software Engineer
Technical Screen
Coding & Algorithms
Easy

38

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
Hash maps and frequency counting
Edge cases and input validation
Sorting and searching
Dynamic programming and memoization
Graph algorithms and traversal
Data structure selection and trade-offs
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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
  1. Initialize an empty dictionary: This will hold our adjacency list.
  2. Split the input string by semicolons to separate each connection.
  3. Iterate through each connection: For each conn...

Submit Your Answer
Markdown supported

Related Questions