Equation division queries

Write codeHard35 minGoogle style

Your task

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.

Examples

evaluate_ratios(equations: list[list[str]], values: list[float], queries: list[list[str]]) -> list[float]
Example 1
Inputevaluate_ratios([["a", "b"], ["b", "c"]], [2, 3], [["a", "c"], ["b", "a"], ["a", "e"], ["x", "x"]])
Output[6, 0.5, -1, -1]