Base Unit Conversions
Updated
Problem statement
There are n types of units, numbered from 0 to n - 1. You are given a 2D integer array conversions with n - 1 rows. Each row [sourceUnit, targetUnit, conversionFactor] means that one unit of type sourceUnit is worth conversionFactor units of type targetUnit.
Unit 0 is the base unit. Starting from it, you can reach every other unit by following conversions forward, and there is exactly one way to do so for each unit.
Return an array baseUnitConversion of length n, where baseUnitConversion[i] is the number of units of type i that are worth one unit of type 0. These numbers can be very large, so return each one modulo 10^9 + 7.
Function
baseUnitConversions(conversions: int[][]) → int[]Examples
Example 1
conversions = [[0,1,3],[1,2,4]]return = [1,3,12]- Unit
0is the base, so its value is1. - One unit
0equals3units of type1. - Each unit
1equals4units of type2, so one unit0equals3 * 4 = 12units of type2.
Example 2
conversions = [[2,3,5],[0,2,10],[0,1,2]]return = [1,2,10,50]- The conversions are not listed from the base outward:
[2, 3, 5]comes before unit2is known. - From unit
0: unit2is10and unit1is2. - Unit
3hangs off unit2:10 * 5 = 50. - The answer is
[1, 2, 10, 50].
Example 3
conversions = [[0,1,1000000000],[1,2,1000000000]]return = [1,1000000000,49]- Unit
1is1000000000, which is below10^9 + 7, so it stays as is. - Unit
2is10^18. Since10^9is7less than10^9 + 7, the product leaves the same remainder as(-7) * (-7) = 49. - The answer is
[1, 1000000000, 49].
Constraints
2 <= n <= 1000conversions.length == n - 1conversions[i] == [sourceUnit, targetUnit, conversionFactor]0 <= sourceUnit, targetUnit < n1 <= conversionFactor <= 10^9- Unit
0can be converted into every other unit through exactly one chain of forward conversions.
More Adobe Online Assessment questions
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Top-Funded Villages and ProjectsOA · Seen Aug 2026
- Count Parent Nodes With a Target SumOA · Seen Aug 2026
- Largest Binary Number by ConcatenationOA · Seen Aug 2026
- Count Events by CategoryOA · Seen Aug 2026
- Graph M-ColoringOA · Seen Aug 2026
- Hall of Shifting TilesOA · Seen Aug 2026
- K-th Ancestor Subtree Preorder QueryOA · Seen Aug 2026
- Maze ReachabilityOA · Seen Aug 2026
- Minimum Numeric Code TransformationOA · Seen Aug 2026
Similar questions at other companies
- Maximum Data Transfer TimeMicrosoft · OAMicrosoft interview questions
- Longest Transfer Time in a Server TreeRippling · OARippling interview questions
- Special Diameter EndpointsAgoda · OAAgoda interview questions
- Diameter of an Acyclic Undirected GraphSalesforce · ONSITE INTERVIEWSalesforce interview questions
- All Nodes Distance K in a Binary TreeAmazon · PHONE SCREEN
- Tree DiameterQualcomm · PHONE SCREENQualcomm interview questions
- Frog Position After T SecondsInMobi · PHONE SCREENInMobi interview questions
- Part 1: The Narrowest KeyScale AI · OAScale AI interview questions
- Tree Pythagorean TriplesIBM · OAIBM interview questions
- Minimum Cleaning Robot RunsHSBC · OAHSBC interview questions
Interview reports that mention this question
Adobe interview experiences
- Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
- Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
- Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
- Adobe New Grad MTS Interview Questions: 7 Experiences
- Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)