Yahoo: Convert between units through known ratios
Problem. You are given conversion facts such as feet to inches and inches to centimetres. Answer queries that convert a value from one unit to another, even when there is no direct rule between them.
Approach discussed. Treat each unit as a node and each conversion as a weighted edge, with the reverse edge holding the inverse ratio. For a query, run BFS (or DFS) from the source unit and multiply ratios along the path. Return a not-found answer if the target is unreachable.
Context. Asked as the coding part of a first round for a senior role, after resume and project questions.
Comments 0
No comments yet. Ask the author something, or add what happened in your own round.