← 返回 uber 的题目列表Evaluate Division
类型:qbank
You are given equations such as A / B = k, represented by equations[i] = [A, B] and values[i] = k. For each query [C, D], return the value of C / D if it can be derived from the given equations, or -1.0 otherwise.
Evaluate Division
You are given equations such as A / B = k, represented by equations[i] = [A, B] and values[i] = k. For each query [C, D], return the value of C / D if it can be derived from the given equations, or -1.0 otherwise.
SWE
graph
dfs
union-find
medium
Frequency
Single report
Last asked
2026-02-15
Stage
phone-screen
Evaluate Division
You are given equations such as A / B = k, represented by equations[i] = [A, B] and values[i] = k.
For each query [C, D], return the value of C / D if it can be determined from the given equations, or -1.0 otherwise.
Examples
Example 1:
Input: equations = [["a","b"],["b","c"]], values = [2.0,4.0], queries = [["a","c"],["c","a"],["a","e"]]
Output: [8.0,0.125,-1.0]
Constraints
1 <= equations.length <= 20
values.length == equations.length
1 <= queries.length <= 20
Variable names are non-empty strings.