FastPrepMinimum Path Cost with Edge Discounts
Problems/Minimum Path Cost with Edge Discounts

Minimum Path Cost with Edge Discounts

Skyscanner logoSkyscanner● HardFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Skyscanner onsite interview. The report describes a live-coding problem similar to Minimum Cost to Reach City With Discounts. Our graph version follows that named task and is about 98% the same as the reported question.

You are given an undirected graph with nodes 0 through n - 1. Each edge [u, v, weight] has a positive integer cost.

Travel from node 0 to node n - 1. You may apply at most discounts discounts, each to a different traversal of an edge; a discounted edge costs floor(weight / 2). Return the minimum possible path cost, or -1 when the destination is unreachable.

Function

minimumPathWithDiscounts(n: int, edges: int[][], discounts: int) → long

Examples

Example 1

n = 5edges = [[0,1,4],[1,4,8],[0,2,2],[2,3,2],[3,4,10]]discounts = 1return = 8

Path 0-1-4 costs 4 + floor(8/2) = 8.

Example 2

n = 3edges = [[0,1,5]]discounts = 2return = -1

Node 2 is unreachable.

Constraints

  • 2 <= n <= 10000.
  • 0 <= edges.length <= 50000.
  • 1 <= weight <= 1000000000.
  • 0 <= discounts <= 20.

Similar questions at other companies

  • Shortest Paths in a Nonnegative Directed GraphNation with NaMo · PHONE SCREEN
  • Fuel Route with Fewest Station VisitsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Cheapest Flight with Its PathAirbnb · OA · PHONE SCREEN · ONSITE INTERVIEWAirbnb interview questions
  • Maximum Gain on a Budgeted Returning WalkNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
  • Cheapest Flights Within K StopsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Path With Maximum ProbabilitySalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Cheapest Flights Within K StopsGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Dijkstra's Shortest PathsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Single-Source Shortest PathsRippling · ONSITE INTERVIEWRippling interview questions
  • Minimum-Weight Path Through a MatrixMeta · ONSITE INTERVIEWMeta interview questions
All Skyscanner interview questionsSee Skyscanner hiring insights
Saved
class Solution {
    public long minimumPathWithDiscounts(int n, int[][] edges, int discounts) {
        // Write your code here.
    }
}
Checking account…