Evaluate Division

You are given an array of variable pairs and an array of real numbers where each pair and number represent a division equation. You must answer queries that ask for the result of dividing one variable by another. If a query cannot be resolved, return -1.0.

Constraints

  • 1 <= equations.length <= 20
  • equations[i].length == 2
  • 1 <= A_i.length, B_i.length <= 5
  • values.length == equations.length
  • 0.0 < values[i] <= 20.0
  • 1 <= queries.length <= 20
  • queries[i].length == 2
  • 1 <= C_j.length, D_j.length <= 5
  • A_i, B_i, C_j, D_j consist of lower case English letters and digits.
Saving… · 2 lines
class Solution:
def evaluate_division(self, equations: List[Tuple[str, str]], values: List[float], queries: List[Tuple[str, str]]) -> List[float]:
Console

Click Run to execute sample tests.