Transform linked list to adjacency list

Last updated: January 21, 2026

Quick Overview

Given a singly linked list where each node contains a value and a reference to the next node, transform this linked list into an adjacency list representation of a graph. Each node's value should be used as a key in the adjacency list, with its corresponding value being a list of all the nodes it is directly connected to. The output should be a dictionary where each key is a node's value and the value is a list of connected nodes' values.

Notion
Coding & Algorithms
Software Engineer
Notion
January 21, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Hard

10

3

4,958 solved


Given a singly linked list where each node contains a value and a reference to the next node, transform this linked list into an adjacency list representation of a graph. Each node's value should be used as a key in the adjacency list, with its corresponding value being a list of all the nodes it is directly connected to. The output should be a dictionary where each key is a node's value and the value is a list of connected nodes' values.

This coding problem is frequently asked during Phone Screen at Notion. The interviewer is testing your ability to translate a problem into clean, working code while discussing time and space complexity. Notion expects candidates to write production-quality code, not just solve the puzzle.

What the Interviewer Expects
  • Quickly identify the optimal approach and its theoretical basis
  • Handle complex algorithm design with multiple interacting components
  • Write concise, elegant code under time pressure
  • Prove correctness of your approach and discuss alternative solutions
  • Optimize beyond the obvious: discuss constant factor improvements
  • Address follow-up variations and explain how the solution generalizes
Key Topics to Cover
Tree structures and recursion
Graph algorithms and traversal
Common algorithm patterns (sliding window, two pointers, BFS/DFS)
Dynamic programming and memoization
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
  • Can you solve this iteratively instead of recursively (or vice versa)?
  • What is the worst-case input for your solution?
  • What happens if the input contains duplicates?
  • 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 transforming a singly linked list into an adjacency list representation of a graph. Each node in the linked list has a value and a reference to the next node. Thus, the adjacency ...

Approach
  1. Initialize an empty dictionary to store the adjacency list.
  2. Traverse the linked list starting from the head node.
  3. For each node, check if it has a next node:
    • If it does, ad...

Submit Your Answer
Markdown supported

Related Questions