Cheapest Delivery Route Using Up to K Half Price Vouchers

Last updated: November 29, 2026

Quick Overview

Given directed logistics legs between hubs with costs in yen, find the minimum cost from a source hub to a destination when up to k legs may be paid at half price.

Rakuten
Coding & Algorithms
Software Engineer
Rakuten
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Given directed logistics legs between hubs with costs in yen, find the minimum cost from a source hub to a destination when up to k legs may be paid at half price.

Rakuten operates its own fulfillment and delivery network alongside third-party carriers, so routing with discounts is a plausible domain. The onsite interviewer is testing whether you expand the state space to (node, vouchers used) and still run Dijkstra correctly.

What the Interviewer Expects
  • Recognize plain Dijkstra fails because voucher placement matters
  • Expand state to (hub, vouchers used)
  • Relax both the full-price and the discounted edge
  • Return as soon as the destination is popped
  • State O((V k + E k) log(V k)) complexity
Key Topics to Cover
Dijkstra
state space expansion
shortest paths
priority queues
graph modeling
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Vouchers can only be used on legs operated by partner carriers. What changes?
  • Instead of a voucher count, you have a total discount budget in yen.
  • The graph has a million hubs. Would A* help, and what heuristic is admissible?
  • How would you return the actual path and which legs used vouchers?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Hubs are 0..n-1, legs are directed (u, v, cost) with non-negative costs. At most k legs can be halved (integer division is fine since costs are even yen amounts). Return the min total or -1 if the d...

High-Level Design

Greedily halving the most expensive leg on the plain shortest path is wrong, because a longer path with one very expensive leg can become cheapest after halving. The fix is a layered graph: state `(hu...


Submit Your Answer
Markdown supported

Related Questions