← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Given a list of equations representing an equation system and a list of queries, return the result of each query. Equations of the form A / B = k are given, and for each query C / D, determine the result. If the result cannot be determined from the given equations, return -1.0.
Input:
equations = [["a","b"],["b","c"]], values = [2.0, 3.0], queries = [["a","c"],["b","a"],["a","e"],["a","a"],["x","x"]]
Output:
[6.0, 0.5, -1.0, 1.0, -1.0]
Explanation:
"a" / "c", we have "a" / "b" = 2 and "b" / "c" = 3. Therefore, "a" / "c" = 2 * 3 = 6."b" / "a", we have "a" / "b" = 2. Therefore, "b" / "a" = 1 / 2 = 0.5."a" / "e", we do not have enough information to determine the result, so we return -1.0."a" / "a", we return 1.0 since any number divided by itself is 1."x" / "x", we return -1.0 as we do not have information about "x".1 <= equations.length <= 20equations[i].length == 21 <= values.length == equations.length <= 200.0 < values[i] <= 20.01 <= queries.length <= 20queries[i].length == 2equations[i][0] and equations[i][1] are different letters.queries[i][0] and queries[i][1] are different letters.