Code Room
CodingHardcod-g497
Subject Union findLevel Senior–Staff~35 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

You are given equations as pairs of variable names and a parallel list of values, where equations[i] = [Ai, Bi] and values[i] = k means Ai / Bi = k (all values positive). For each query [Cj, Dj], compute Cj / Dj if it is determinable from the equations, otherwise return -1.0 for that query. A query involving a variable that never appears in any equation returns -1.0. Return the list of answers in query order. There are at most 200 equations and 200 queries.

Implement
evaluate_ratios(equations: list[list[str]], values: list[float], queries: list[list[str]]) → 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.