Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Write a Programming Function

HardPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Write a Programming Function. Start with the requirements on the right.

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.

Problem

UNT Health Science Center logistics routes connect campus locations through directed paths. Each route has a travel time and an operational cost. Find the fastest route from a source location to a destination while staying within a cost budget and using at most a specified number of time-reduction coupons.

A coupon may be applied to any traversed route and changes its travel time from time to max(1, floor(time / 2)). Each coupon can be used once, and unused coupons are allowed. Return the minimum travel time and one route achieving it. If no valid route exists, return [-1, []].

Formal Specification

Implement route_with_budget(n, edges, start, destination, budget, coupons). n is the number of locations labeled 0 through n - 1. edges is a list of [from, to, time, cost] entries representing directed routes. Return [minimum_time, path], where path is a list of location IDs from start to destination.

Constraints

  • 1 <= n <= 200
  • 0 <= len(edges) <= 2,000
  • 1 <= time <= 10^6
  • 0 <= cost <= budget
  • 0 <= budget <= 200
  • 0 <= coupons <= 10
  • start and destination are valid location IDs
  • Route times are positive; parallel routes may exist

Function Signature

def route_with_budget(n, edges, start, destination, budget, coupons):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output