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
Road Toll Influence
00:00
5 left

Road Toll Influence

HardPython

Problem

There are n cities connected by roads with toll prices; find the road whose toll can be increased so that the average price increase across all routes from city 0 to city n-1 is maximized.

Asked in the DSA round stage. Treat roads as directed edges in a DAG. Increasing one road's toll by 1 increases a route's price by 1 exactly when that route uses the road. Return the zero-based road index, breaking ties by smaller index.

Input: n and roads, where each road is [from, to, toll]. Output: an integer road index.

Constraints

  • 2 <= n <= 1000
  • 1 <= roads.length <= 5000
  • Each road is [from, to, toll].
  • 0 <= from, to < n and from != to.
  • 1 <= toll <= 10^9.
  • The roads form a directed acyclic graph.
  • At least one route exists from city 0 to city n - 1.
  • Parallel roads are allowed.
  • Ties are resolved by the smallest road index.

Function Signature

def max_average_increase(n, roads):
Interviewer

Your question is Road Toll Influence. 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.