The Evaluate Division interview question presents a set of variables and their relationships in the form of equations (e.g., a / b = 2.0). Based on these equations, you are given multiple queries (e.g., a / c = ?) and must calculate the result if it can be determined. If a path of relationships exists between two variables, you can compute the result by multiplying the weights along that path. If no path exists, or if a variable is unknown, you return -1.0.
Companies like Uber, Meta, and Amazon ask the Evaluate Division coding problem to see if you can model abstract relationships as a graph. It tests your proficiency with Graph traversal and your ability to handle numerical precision. It's a "Medium" problem that effectively evaluates if you can identify that a division relationship is just a weighted edge in a directed graph where a / b = k means a -> b with weight k and b -> a with weight 1/k.
This problem is a classic Graph and Shortest Path problem.
x / y, perform a search starting from x to see if y is reachable. While traversing, multiply the weights of the edges.Equations: a / b = 2.0, b / c = 3.0.
Graph:
a --(2.0)--> b, b --(0.5)--> ab --(3.0)--> c, c --(0.33)--> b
Query: a / c?a.b (weight 2.0).b, move to c (weight 3.0).2.0 * 3.0 = 6.0.
Result: 6.0.Whenever you see a problem involving "chaining" ratios or relationships, immediately think of a Weighted Directed Graph. The search for a ratio between two items is simply finding a path between two nodes and aggregating the weights.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Maximize Amount After Two Days of Conversions | Medium | Solve | |
| Sentence Similarity II | Medium | Solve | |
| The Maze III | Hard | Solve | |
| Alien Dictionary | Hard | Solve | |
| Is Graph Bipartite? | Medium | Solve |