Amazon Applied Scientist Coding Round

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2024-04-26Added By Anonymous
Source: Link

Company: Amazon
Role: Applied Scientist
Interview Stage: Coding Round
Location: unknown
Year: unknown

Original Post Content:

You are given the following conversion factors:

"""
kilogram gram 1000
kilogram pound 2.21
feet inch 12
...
"""

Now, given from_unit and to_unit, output the conversion factor and if it isn't possible raise an error.

Ex: (pound, gram) -> 454.54
(pound, inch) -> error

This can be solved by converting the above input to Adjancency Hashmap and then doing a BFS/DFS graph traversal while having the information of conversion_factor as an additional element in the queue/stack state (I used BFS).

Comments