Propagate Unit Conversions Through a Weighted Graph
Quick Overview
Propagate unit conversions through a weighted graph using multiplicative BFS, reversible factors, cycle handling, and explicit consistency and precision assumptions.
Propagate Unit Conversions Through a Weighted Graph
Company: Adobe
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Online Assessment
Given conversion relations and a starting unit with value v, compute the equivalent value in every unit connected to the start. A relation from A to B with factor x means a value in A is multiplied by x to obtain its value in B.
### Constraints & Assumptions
Assume positive nonzero factors, reversible conversions, and consistent relations. Add a reverse edge with factor 1/x. If input instead represents a directed-only conversion graph, omit those reverse edges; the source allows graph/tree formulations and does not settle this distinction.
### Clarifying Questions to Ask
- Are conversions reversible, and can the graph contain cycles?
- Are inconsistent relations possible, and what precision is required?
```hint Carry the converted value along each edge
A path's conversion factor is a product, not a sum.
```
### What a Strong Answer Covers
- Weighted adjacency lists and reverse-factor construction when valid.
- DFS/BFS propagation with visited tracking.
- Unreachable units, cycles, consistency assumptions, and O(V+E) complexity.
### Follow-up Questions
- How would you detect contradictory conversion paths?
- When would exact rational factors be preferable to floating-point multiplication?
Overview: Propagate unit conversions through a weighted graph using multiplicative BFS, reversible factors, cycle handling, and explicit consistency and precision assumptions.
Given conversion relations and a starting unit with value v, compute the equivalent value in every unit connected to the start. A relation from A to B with factor x means a value in A is multiplied by x to obtain its value in B.
Constraints & Assumptions
Assume positive nonzero factors, reversible conversions, and consistent relations. Add a reverse edge with factor 1/x. If input instead represents a directed-only conversion graph, omit those reverse edges; the source allows graph/tree formulations and does not settle this distinction.
Clarifying Questions to Ask Guidance
Are conversions reversible, and can the graph contain cycles?
Are inconsistent relations possible, and what precision is required?
What a Strong Answer Covers Guidance
Weighted adjacency lists and reverse-factor construction when valid.
DFS/BFS propagation with visited tracking.
Unreachable units, cycles, consistency assumptions, and O(V+E) complexity.
Follow-up Questions Guidance
How would you detect contradictory conversion paths?
When would exact rational factors be preferable to floating-point multiplication?