MEDIUMasked at 1 company

Minimum Cost to Reach City With Discounts

A medium-tier problem at 60% community acceptance, tagged with Graph, Heap (Priority Queue), Shortest Path. Reported in interviews at Flipkart and 0 others.

Founder's read

Flipkart has asked this problem, and it's not a gimme. You've got a graph, you need shortest path, but there's a twist: discounts that change the cost calculation mid-route. Half the candidates who see it blank on how discounts interact with Dijkstra's algorithm, then second-guess themselves on state representation. The acceptance rate sits at 60%, which means 40% of submissions fail because they either ignore the discount mechanic or build a state space that explodes. If this lands on your live OA and you hit the wall, StealthCoder surfaces the working approach in seconds, invisible to the proctor.

Companies asking
1
Difficulty
MEDIUM
Acceptance
60%

Companies that ask "Minimum Cost to Reach City With Discounts"

If this hits your live OA

Minimum Cost to Reach City With Discounts is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE.

Get StealthCoder
What this means

The trap is treating this like vanilla Dijkstra. You can't just run shortest path once because discounts change what 'shortest' means on your second traversal. You need to track not just distance but also whether you've used your discount. This becomes a shortest-path problem where the state is (node, discount_used), not just (node). Build your priority queue with (cost, node, discount_status), then explore neighbors from each state. Common failure: forgetting that the discount applies to future edges once activated, or trying to precompute discount values and missing that timing matters. Another pitfall is implementing Dijkstra correctly for a single-state graph but then not extending it cleanly to the dual-state version. StealthCoder handles the state transition logic automatically when you're live, so even if the concept feels fuzzy during the assessment, you get a passing solution.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Minimum Cost to Reach City With Discounts recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Minimum Cost to Reach City With Discounts interview FAQ

Is this really just Dijkstra with extra state?+

Yes. Core algorithm is Dijkstra, but instead of (node) as your state, you use (node, discount_used_flag). Priority queue stores (cost, node, flag). Each state needs its own visited check. If you've done vanilla Dijkstra before, this is the natural extension once you realize discounts create two versions of each node.

Why is the acceptance rate only 60% if it's 'just' Dijkstra?+

Because the state-space doubling confuses people. Many implement Dijkstra correctly but forget to track discount usage separately, collapsing states incorrectly. Others implement it right but have off-by-one errors in when the discount activates. The problem is medium difficulty because the concept is straightforward but execution has sharp corners.

How do I know when to activate my discount on the live OA?+

You don't precompute that. Let Dijkstra decide. Explore both options (using discount now vs later) and let the algorithm find which path is actually cheaper. If you're tempted to greedily activate the discount early, stop. The optimal node to activate it on isn't obvious until you've computed distances.

Does this relate to other shortest-path problems I've drilled?+

Directly. If you know Dijkstra with constraints (like 'K stops at most'), this is the same pattern: expand state from (node) to (node, constraint_value). Same heap-based exploration. The Graph and Heap topics are tight here because you're building a multi-level shortest path.

What's the most common wrong submission on this problem?+

Running Dijkstra once with a global discount applied to all edges, instead of exploring both branches (discount used / not used). Another frequent mistake: modifying edge weights globally and re-running Dijkstra separately, which is slower and conceptually wrong. Single pass with dual state is correct.

Want the actual problem statement? View "Minimum Cost to Reach City With Discounts" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.