 All Problems
Evaluate Division
medium
union-find
graph
bfs
google
facebook
amazon

You are given equations in the format A / B = k and some queries. Return the answers to all queries. If an answer does not exist, return -1.0.

Example:

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]

Constraints:

  • 1 <= equations.length <= 20
  • 1 <= queries.length <= 20
Run to check your code against the sample cases, or submit to run every case