PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Instacart

Evaluate query ratios from equations

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's skill in modeling variable ratios as relational structures, reasoning about transitive numeric relationships, and handling disconnected variables and edge cases.

  • hard
  • Instacart
  • Coding & Algorithms
  • Software Engineer

Evaluate query ratios from equations

Company: Instacart

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

You are given equations of the form `A / B = value` where `A` and `B` are variable names (strings) and `value` is a positive real number. You also receive queries of the form `X / Y = ?`. For each query, return the computed ratio if it can be derived from the known equations; otherwise return `-1.0`. **Input** - `equations`: list of pairs `[Ai, Bi]` - `values`: list of doubles where `values[i]` corresponds to `Ai / Bi` - `queries`: list of pairs `[Xj, Yj]` **Output** - Array of doubles where each element is the answer for the corresponding query. **Notes / Constraints** - Variables not appearing in any equation make related queries impossible. - You may assume there are no contradictions. - Aim for a graph + DFS/BFS solution. **Example** - `equations = [["a","b"],["b","c"]]`, `values = [2.0, 3.0]` - `queries = [["a","c"],["c","a"],["a","e"],["a","a"],["x","x"]]` - Output: `[6.0, 1/6, -1.0, 1.0, -1.0]`

Quick Answer: This question evaluates a candidate's skill in modeling variable ratios as relational structures, reasoning about transitive numeric relationships, and handling disconnected variables and edge cases.

Related Interview Questions

  • Implement an In-Memory File Storage System - Instacart (medium)
  • Decode an encoded string - Instacart (medium)
  • Evaluate an arithmetic expression - Instacart (medium)
  • Implement worker time and payroll tracker - Instacart (hard)
  • Solve Two Sorted-Array Tasks - Instacart (hard)
Instacart logo
Instacart
Jan 22, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
7
0
Loading...

You are given equations of the form A / B = value where A and B are variable names (strings) and value is a positive real number.

You also receive queries of the form X / Y = ?. For each query, return the computed ratio if it can be derived from the known equations; otherwise return -1.0.

Input

  • equations : list of pairs [Ai, Bi]
  • values : list of doubles where values[i] corresponds to Ai / Bi
  • queries : list of pairs [Xj, Yj]

Output

  • Array of doubles where each element is the answer for the corresponding query.

Notes / Constraints

  • Variables not appearing in any equation make related queries impossible.
  • You may assume there are no contradictions.
  • Aim for a graph + DFS/BFS solution.

Example

  • equations = [["a","b"],["b","c"]] , values = [2.0, 3.0]
  • queries = [["a","c"],["c","a"],["a","e"],["a","a"],["x","x"]]
  • Output: [6.0, 1/6, -1.0, 1.0, -1.0]

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Instacart•More Software Engineer•Instacart Software Engineer•Instacart Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.