Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Currency Exchange Rates
00:00
5 left

Currency Exchange Rates

HardPython

Problem

Given a list of currency relationships with exchange values (e.g. BTC - USD), find the best exchange rate from currency1 to currency2.

Each relationship is directed: [source, destination, rate] means one unit of source becomes rate units of destination. Return the maximum product of rates along any simple path. Return 1.0 when both currencies are equal and 0.0 when the destination is unreachable. Asked in the coding round 1 stage. Edge cases like self loops expected.

Function: def best_exchange_rate(rates, currency1, currency2):

rates is a list of [string, string, float] values. Do not reuse a currency within one path.

Constraints

  • 1 <= rates.length <= 1000
  • Each relationship has the form [source, destination, rate]
  • source and destination are non-empty strings
  • 0 < rate <= 10^6
  • currency1 and currency2 are non-empty strings
  • A path may not visit the same currency more than once

Function Signature

def best_exchange_rate(rates, currency1, currency2):
Interviewer

Your question is Currency Exchange Rates. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.