Unit Conversion II - Problem
Unit Conversion II is an advanced graph traversal problem that simulates a unit conversion system.
You're given
For each query
Key Challenge: Handle indirect conversions (A→C via A→B→C) and return mathematically correct fractions modulo 10⁹ + 7.
You're given
n types of units (indexed 0 to n-1) and a 2D array conversions where conversions[i] = [sourceUnit, targetUnit, conversionFactor] means that 1 unit of sourceUnit = conversionFactor units of targetUnit.For each query
[unitA, unitB], you need to find how many units of unitB are equivalent to 1 unit of unitA. The answer should be expressed as a fraction p/q in lowest terms, then return p × q⁻¹ mod (10⁹ + 7) where q⁻¹ is the modular multiplicative inverse of q.Key Challenge: Handle indirect conversions (A→C via A→B→C) and return mathematically correct fractions modulo 10⁹ + 7.
Input & Output
Constraints
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code