# Leetcode 399 - Evaluate Division

`Note:`

`DFS`

- Use
`map`

to construct a graph. Note that for every`[a, b]`

,`[b, a]`

should also be added. - Use
`valMap`

to store vals. - Based case of DFS:
`map`

doesn’t have`curr`

OR`curr`

has been visited before. Return`-1`

. - Params :
`curr`

`dest`

known from query`product`

contains result (Next product should be`product * valmap.get(curr + '.' + neighbor)`

).

- While result from
`dfs()`

is not`-1`

, return it. Otherwise return -1.

- Use

`Question:`

You are given an array of variable pairs `equations`

and an array of real numbers `values`

, where `equations[i] = [Ai, Bi]`

and `values[i]`

represent the equation `Ai / Bi = values[i]`

. Each `Ai`

or `Bi`

is a string that represents a single variable.

You are also given some `queries`

, where `queries[j] = [Cj, Dj]`

represents the `jth`

query where you must find the answer for `Cj / Dj = ?`

.

Return the answers to all queries. If a single answer cannot be determined, return `-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.

`Example:`

1 | Input: equations = [["a","b"],["b","c"]], values = [2.0,3.0], queries = [["a","c"],["b","a"],["a","e"],["a","a"],["x","x"]] |

`Code:`

1 | /** |