Unweighted Directed Graph

Question

You are given a list of node edges, u and v, where u has a path to v. Create an unweighted, directed graph using an adjacency list and return it. The graph should be represented using a dictionary.

Note: Nodes with no outgoing edges don't need to be explicitly included in the returned graph.

Input: edges = [(1, 2), (1, 3), (2, 3)]

Output: {1: [2, 3], 2: [3]}

Input: edges = [(1, 2), (2, 3), (2, 4)]

Output: {1: [2], 2: [3, 4]}

Clarify the problem

What are some questions you'd ask an interviewer?

Understand the problem

What graph should be returned, given the following edges? edges = [(1, 2), (1, 4), (2, 3), (4, 2)]
{2: [1, 4], 3: [2], 4: [1]}
{1: [2, 4], 2: [3], 4: [2]}
{1: [2, 4], 2: [3], 3: [], 4: [2]}
{1: [2], 2: [3], 4: [2]}

Take a moment to understand the problem and think of your approach before you start coding.