The "Check for Contradictions in Equations interview question" involves validating a system of mathematical relationships. You are given equations like A / B = 2.0 and B / C = 3.0. Your task is to determine if a new equation (or the set itself) contradicts existing information. A contradiction occurs if, for example, the input says A / C = 5.0 when the previous equations implied A / C = 6.0.
Uber and Amazon use the "Check for Contradictions coding problem" to evaluate a candidate's ability to model relationships as a graph. It tests knowledge of Union Find (with weights) or Graph Traversal (DFS/BFS). It evaluations your ability to manage floating-point precision and perform path-based calculations in a directed, weighted graph.
This problem follows the Union Find with Weights or Graph Reachability pattern.
X / Y = val as a directed edge from X to Y with weight val (and an edge from Y to X with weight 1/val).A and C, find any path between them and multiply the weights along that path.Equations: [A/B=2, B/C=3, A/C=5]
A/B=2: Node A and B are linked.B/C=3: Node B and C are linked. Implied A/C = (A/B) * (B/C) = 2 * 3 = 6.A/C=5: New information! But we already calculated A/C = 6.== instead of checking if the difference is within a small range.This is a variation of the "Evaluate Division" problem. Practice using Union Find to store relative weights. In this "Graph interview pattern," the "root" of each component can store the ratio of each node relative to the root, making comparisons .
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Minimum Time to Break Locks II | Hard | Solve | |
| Minimize Hamming Distance After Swap Operations | Medium | Solve | |
| Minimize Malware Spread II | Hard | Solve | |
| Minimize Malware Spread | Hard | Solve | |
| Maximum Partition Factor | Hard | Solve |