Evaluate Division

Try to solve the Evaluate Division problem.

Statement

You are given an array of variable pairs equations and an array of real numbers, values, where the equations[i] = [A[i], B[i]] and values[i] represent the equation values[i] = A[i] / B[i]

Each A[i] or B[i] is a string that represents a single variable.

You are also given some queries, where queries[j] = [C[j], D[j]] represents the jthj^{th} query where you must find the answer for C[j] / D[j].

Return the answers to all queries. If any single answer cannot be determined, return 1.0-1.0.

Note: The input is always valid. You may assume that evaluating the queries will not result in division by zero and that there is no contradiction.

Constraints:

  • 11 \leq equations.length 20\leq 20

  • equations[i].length ==2== 2

  • 11 \leq A[i].length, B[i].length 5\leq 5

  • values.length ==== equations.length

  • 0.0<0.0 < values[i] 20.0\leq 20.0

  • 11 \leq queries.length 20\leq 20

  • queries[i].length ==2== 2

  • 11 \leq C[j].length, D[j].length 5\leq 5

  • A[i], B[i], C[j], D[j] consist of lower case English letters and digits.

Examples

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy