Weighted Directed Graph

Question

You are given a map of node edges in the form, (u, v): w, where u has a path to v and w is edge weight. Create a weighted, directed graph using an adjacency list.

Input: weighted_edges = {(1, 2): 50, (1, 3): 20, (2, 3): 40}

Output: {1: [(2, 50), (3, 20)], 2: [(3, 40)]}

Input: weighted_edges = {(1, 2): 350, (2, 3): 960, (2, 4): 2550}

Output: {1: [(2, 350)], 2: [(3, 960), (4, 2550)]}

Clarify the problem

What are some questions you'd ask an interviewer?

Understand the problem

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

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