Design an Extensible Unit Conversion Library Behind Search Answers

Last updated: November 29, 2026

Quick Overview

Design a library that answers queries like how many kilometers in 3 miles, where units are registered with pairwise factors, conversions may require chaining several factors, and converting across incompatible dimensions is rejected.

Google
Software Engineering Fundamentals
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Software Engineering Fundamentals
Medium

0

0

0 solved


Design a library that answers queries like how many kilometers in 3 miles, where units are registered with pairwise factors, conversions may require chaining several factors, and converting across incompatible dimensions is rejected.

Google Search answers unit conversions directly, and this question blends OOD with a graph traversal. The interviewer checks how units and dimensions are modeled, how an unregistered pair is resolved by path finding, and awareness of precision and affine units like temperature.

What the Interviewer Expects
  • Models units as graph nodes with multiplicative edges in both directions
  • Finds a conversion path with BFS or DFS and multiplies factors
  • Tags units with a dimension to reject incompatible conversions early
  • Uses exact arithmetic to avoid accumulating floating-point error
  • Recognizes temperature needs an offset, not just a factor
Key Topics to Cover
graph traversal
OOD
exact arithmetic
dimensional analysis
extensibility
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How would you support Celsius to Fahrenheit?
  • How would you handle compound units such as miles per hour or kilowatt hours?
  • How would you make repeated conversions O(1)?
  • How would you detect inconsistent factors registered by different teams?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements
  • add(a, b, factor, dimension) means 1 a equals factor b.
  • convert(value, src, dst) works even when only indirect factors exist.
  • Reject unknown units and mismatched dimensions with clear errors...
High-Level Design

Store a bidirectional weighted graph: edge a to b has weight f, b to a has 1/f. Each unit is tagged with its dimension at registration, and a unit cannot switch dimensions. A conversion runs BFS from ...


Submit Your Answer
Markdown supported