Cheapest Ad Delivery Path Under a Hard Latency Deadline
Last updated: November 29, 2026
Quick Overview
Ad requests travel through a network of nodes where each hop takes some time and each node visited charges a processing fee. Return the minimum total fee to get from node 0 to node n-1 within maxTime, or -1 if no route meets the deadline.
Meta
November 29, 20260
0
0 solved
Ad requests travel through a network of nodes where each hop takes some time and each node visited charges a processing fee. Return the minimum total fee to get from node 0 to node n-1 within maxTime, or -1 if no route meets the deadline.
A Meta onsite question about constrained shortest paths, where minimizing one quantity is subject to a budget on another. It maps to ads delivery, where an auction must finish within a latency budget while minimizing compute cost. Interviewers watch for the Pareto pruning idea rather than a naive state explosion.
What the Interviewer Expects
- Identify a two-criteria shortest path: minimize fee subject to time
- Explain why plain Dijkstra on fee alone is wrong
- Use Pareto pruning: only revisit a node with strictly less time
- Contrast with DP over (time, node) and its cost
- Handle no feasible route
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Write the DP over time and node and compare its complexity.
- What if fees are charged per edge instead of per node?
- How would you return the k cheapest feasible routes?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
nup to 1000 nodes, undirected roads(u, v, minutes),fees[i] >= 1,maxTimeup to 1000.- Fees at the start and end nodes count. Revisiting a node pays its fee again.
- Return the minimum to...
High-Level Design
Run Dijkstra ordered by fee, but a node's best state is a pair (fee, time). Popping states in increasing fee means the first pop of a node has the lowest fee to reach it. A later pop is only useful if...