FastPrepChoose a Road to Maximize Average Route Toll Increase
Problems/Choose a Road to Maximize Average Route Toll Increase

Choose a Road to Maximize Average Route Toll Increase

Harness logoHarness● HardFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives the task and the interview setting. We rebuilt the function signature, the tie-breaking rule, the examples, and the input limits to match the report as closely as we could. Our version is about 90% the same as the reported question.

A directed acyclic graph has cities 0 through n-1. Each road is [from,to,toll]. Every route means a directed path from city 0 to city n-1.

Increase exactly one road's toll by one. Return the zero-based input index that maximizes the average toll increase across all routes. Roads on no complete route contribute zero; break ties by smaller input index. Return -1 when no route exists.

Function

bestRoadToIncrease(n: int, roads: int[][]) → int

Examples

Example 1

n = 4roads = [[0,1,5],[0,2,1],[1,3,2],[2,3,9]]return = 0

Every road belongs to one of two routes, so index zero wins the tie.

Example 2

n = 4roads = [[0,1,1],[1,2,1],[1,3,1],[2,3,1]]return = 0

Road 0 appears on both complete routes.

Example 3

n = 3roads = [[0,1,2]]return = -1

No route reaches the destination.

Constraints

  • 2 <= n <= 100000.
  • The graph is a DAG.
  • Path counts fit in a signed 64-bit integer.

More Harness interview questions

  • Minimum MovesOA · Seen Oct 2026
  • Encode and Decode a String StreamONSITE INTERVIEW · Seen Sep 2026
  • Streaming Ingredient DishesONSITE INTERVIEW · Seen Jul 2026

Similar questions at other companies

  • Select Transactions with Child-Pays-for-Parent PackagesCoinbase · PHONE SCREENCoinbase interview questions
  • Parallel Courses with DurationsCitadel · PHONE SCREENCitadel interview questions
  • All Halfway Courses Across Course TracksCrunchyroll · PHONE SCREENCrunchyroll interview questions
  • Minimum Completion Time for DAG DependenciesAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Work Order Critical PathHadrian · PHONE SCREENHadrian interview questions
  • Longest Name Chain in a Directed Acyclic GraphOscar Health · PHONE SCREEN
  • Service Dependency Load FactorsRobinhood · PHONE SCREENRobinhood interview questions
  • Longest Chain BookingAirbnb · PHONE SCREENAirbnb interview questions
  • Critical Path Through Dependent TasksModular · PHONE SCREEN · ONSITE INTERVIEW
  • Earliest Dataset Readiness in a PipelinexAI · PHONE SCREENxAI interview questions
See Harness hiring insights
Saved
class Solution {
    public int bestRoadToIncrease(int n, int[][] roads) {
        // write your code here
    }
}
Checking account…