Code Room
CodingMediumcod-g867
Subject Expression evaluationLevel Mid–Senior~30 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

You are given a list of equations like `["a","b"]` meaning `a / b = value`, plus the parallel list of positive float `values`. For each query `["x","y"]` return the value of `x / y` computed by chaining known ratios, or `-1.0` if it cannot be determined (an unknown variable or a disconnected pair). A query of a variable with itself, if the variable is known, is `1.0`. Round each answer to 5 decimal places.

Implement
evaluate_division(equations: list[list], values: list[float], queries: list[list]) → list[float]
Examples
in[[["a","b"],["b","c"]],[2,3],[["a","c"],["b","a"],["a","e"],["x","x"]]]out[6,0.5,-1,-1]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.