Currency Conversion Interview Problem (Python)

Python Interview with a Microsoft engineer

Watch someone solve the currency conversion problem in an interview with a Microsoft engineer and see the feedback their interviewer left them. Explore this problem and others in our library of interview replays.

Interview Summary

Problem type

Currency Conversion

Interview question

Given the above parameters, find the conversion rate that maps to the 'from' currency to the 'to' currency for every single query

Interview Feedback

Feedback about Crimson Almond (the interviewee)

Advance this person to the next round? Yes
How were their technical skills? 4/4
How was their problem solving ability? 4/4
What about their communication ability? 4/4

🎉 Summary: Interviewee is very solid, if I interviewed him at Microsoft for an Intern position, whether it's a technical phone screen or a virtual onsite, It would be a pass for me.

Interview Transcript

Crimson Almond: Hello! Can you hear me?
Winter Pumpkin: Yeah I can hear you.
Crimson Almond: Just is my voice audible.
Winter Pumpkin: Yes, I can hear your voice pretty well.
Crimson Almond: Alright all good. Yo how's your day been?
Winter Pumpkin: Yeah, I'm doing pretty good. How was yours?
Crimson Almond: Fantastic. Thanks for asking again.

Crimson Almond: Yeah, thank you. So right now, I am a third. I'm a college student. I am a third year, computer science major. I go to a public school in California. And tomorrow, actually, I have an intern interview coming up for amazon.

Winter Pumpkin: Cool. So yeah, my name is Derek and I work in the operation analytics team. We do a lot of dashboarding.

Crimson Almond: Yeah, so if you don't mind, just kind of let me know like, you know, what you're looking for currently? How can I support you?

Winter Pumpkin: If you could go to Line 80.

Crimson Almond: Alright. Yes. So...

Coding Task

from typing import List, Dict

def get_conversions(rates: List[List[str]], queries: List[List[str]]) -> List[float]:
    adjacency_list = {}
    for rate in rates:
        from_currency, to_currency, conversion_rate = rate[0], rate[1], float(rate[2])
        adjacency_list.setdefault(from_currency, []).append((to_currency, conversion_rate))
        adjacency_list.setdefault(to_currency, []).append((from_currency, 1/conversion_rate))
    results = []
    for query in queries:
        src, dst = query[0], query[1]
        if src not in adjacency_list or dst not in adjacency_list:
            results.append(-1.0)
            continue
        # Perform BFS or DFS here to find the conversion
        found = False
        # Code for BFS or DFS goes here
        results.append(conversion_result if found else -1.0)
    return results

Suggestions for Improvement

  1. Clarify Input: Clarifying on the input and size to avoid friction during the interview.
  2. Efficiency: Mention the potential impact of floating point division on accuracy over long paths.
  3. Use of Data Structures: Consider using deque for BFS to improve efficiency.
  4. Exception Handling: Adding error handling for unexpected inputs can enhance code robustness.
  5. Refactor Code: Ensure that the code is neat and well-structured to showcase clarity in logic.