FastPrepEvaluate Division
Problems/Evaluate Division

Evaluate Division

Plaud logoPlaud● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Plaud asked this in the second round of an onsite for a new-grad software engineer. The candidate described it only as a value-conversion question similar to a well-known public problem about evaluating division from given ratios, with no further detail.

So the problem follows that well-known public version: ratios between variables are given, and each query asks for the ratio of two variables, or -1.0 when it cannot be derived. We used the public version as is, since the exact variant asked is not known, with its usual limits (up to 20 equations and 20 queries, values above 0 and at most 20, names of 1 to 5 lowercase letters or digits, consistent equations). Answers are accepted within a relative-or-absolute tolerance of 10^-5.

Our version is about 70% the same as the reported question.

You are given equations between variables: equations[i] = [a, b] and values[i] together mean a / b = values[i]. Every value is positive. For example, ["ft", "in"] with value 12 describes a unit conversion: a foot is 12 inches.

For each query [c, d] in queries, return the value of c / d that follows from the equations. Return -1.0 when it cannot be worked out:

  • c or d does not appear in any equation (this includes a query [x, x] when x is unknown), or
  • no chain of equations links c to d.

A query [x, x] returns 1.0 when x appears in at least one equation. Return the answers in the same order as queries. An answer is accepted when it is within 10-5 × max(1, |expected|) of the expected value.

Function

calcEquation(equations: List<List<String>>, values: double[], queries: List<List<String>>) → double[]

Examples

Example 1

equations = [["a","b"],["b","c"]]values = [2.0,3.0]queries = [["a","c"],["b","a"],["a","e"],["a","a"],["x","x"]]return = [6.0,0.5,-1.0,1.0,-1.0]
  • a / c = (a / b) × (b / c) = 2 × 3 = 6, and b / a = 1 / 2 = 0.5.
  • e and x never appear in an equation, so a / e and x / x are -1.0. a / a = 1 because a is known.

Example 2

equations = [["yd","ft"],["ft","in"],["lb","oz"]]values = [3.0,12.0,16.0]queries = [["yd","in"],["oz","lb"],["yd","lb"]]return = [36.0,0.0625,-1.0]
  • yd / in = 3 × 12 = 36: a yard is 3 feet and a foot is 12 inches. oz / lb = 1 / 16 = 0.0625.
  • yd and lb are in different groups that no equation connects, so the answer is -1.0.

Example 3

equations = [["x1","x2"]]values = [0.5]queries = [["x2","x1"]]return = [2.0]
  • x2 / x1 = 1 / 0.5 = 2.

Constraints

  • 1 <= equations.length <= 20
  • equations[i].length == 2 and queries[j].length == 2
  • values.length == equations.length
  • 0.0 < values[i] <= 20.0
  • 1 <= queries.length <= 20
  • Every variable name has 1 to 5 characters, each a lowercase English letter or a digit.
  • The two variables in one equation are different, and the equations never contradict each other.

More Plaud Onsite Interview questions

  • Course ScheduleONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Count Friend CirclesOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Determine Whether Two Horses Are Genetically RelatedGoogle · ONSITE INTERVIEWGoogle interview questions
  • Redundant ConnectionMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Count Connected Components in an Undirected GraphNutanix · ONSITE INTERVIEWNutanix interview questions
  • Connected GroupsFivetran · ONSITE INTERVIEWFivetran interview questions
  • Largest Island After One Land ConversionAmazon · ONSITE INTERVIEW
  • Making a Large IslandMeta · ONSITE INTERVIEWMeta interview questions
  • Largest Island After One Land ConversionBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Evaluate DivisionApple · PHONE SCREENApple interview questions
  • Minimum Unreachable WarehousesVisa · OAVisa interview questions

Interview reports that mention this question

  • Plaud New Grad SWE Onsite Interview Experience: 1 Experience
See Plaud hiring insights
Saved
class Solution {
    public double[] calcEquation(List<List<String>> equations, double[] values, List<List<String>> queries) {
        // Write your code here.
    }
}
Checking account…