As reported: Goldman Sachs Analyst Superday, software engineering practices round that turned into DSA (2025): Evaluate Division, solved with DFS — the interviewer asked to justify the choice — and coded.
You are given equations a / b = value as equations[i] = [a, b] with values[i], and queries[j] = [c, d]. Return the value of each c / d, or -1.0 if it cannot be determined.
This is LeetCode 399 — Evaluate Division.
Example 1
equations = [["a","b"],["b","c"]], values = [2.0,3.0], queries = [["a","c"],["b","a"],["a","e"],["a","a"],["x","x"]]
-> [6.00000,0.50000,-1.00000,1.00000,-1.00000]
Example 2
equations = [["a","b"],["b","c"],["bc","cd"]], values = [1.5,2.5,5.0], queries = [["a","c"],["c","b"],["bc","cd"],["cd","bc"]]
-> [3.75000,0.40000,5.00000,0.20000]
Example 3
equations = [["a","b"]], values = [0.5], queries = [["a","b"],["b","a"],["a","c"],["x","y"]]
-> [0.50000,2.00000,-1.00000,-1.00000]
Constraints: 1 ≤ equations.length ≤ 20; 0.0 < values[i] ≤ 20.0; 1 ≤ queries.length ≤ 20; variable names are short strings.
Code runner format: one JSON value per line: equations, then values, then queries (LeetCode's test-case format). Implement calcEquation(equations, values, queries); the harness prints the result as JSON.