Answer Ratio Queries from Known Quotients

Asked at Uber · Coding Questions · Difficulty: Medium · Last asked Feb 15, 2026

You are given facts of the form "variable `A` divided by variable `B` equals `k`". Using only these facts, answer a list of questions of the form "what is `C` divided by `D`?". A ratio is known when you can derive it by chaining facts, for example `a/b` and `b/c` give `a/c`. If a ratio cannot be derived, the answer is `-1.0`.

Loading the problem…