PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Stripe

How to find the cheapest flight within K stops

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of graph algorithms and constrained shortest-path modeling, focusing on reasoning about weighted directed edges, transfer limits, and cost optimization within a travel network; it belongs to the Coding & Algorithms domain.

  • medium
  • Stripe
  • Coding & Algorithms
  • Software Engineer

How to find the cheapest flight within K stops

Company: Stripe

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Problem 1: Minimize multi-person debt settlement Given a group of people with multiple loan records, find the minimum number of transactions to settle all debts so everyone's balance is zero. Core idea: First compute each person's net balance, and only focus on those whose net amount is non-zero. Then use backtracking or greedy matching to cancel positive and negative amounts against each other. For example, if someone owes 50 and another is owed 50, a single transaction settles both — minimizing the total number of transactions. Follow-up: If the debt relationships are very complex, involving hundreds of people, can your algorithm still maintain efficiency? Problem 2: Cheapest flights within K stops Given a list of flights with prices, find the lowest-cost path from source to destination within K stops. Approach: This is a classic graph shortest-path problem. You can solve it with dynamic programming where dp[i][k] represents the minimum fare to reach node i within k steps. Alternatively, use a modified Dijkstra's algorithm with a priority queue that also tracks the current number of stops, ensuring you don't exceed K stops while finding the lowest price. Follow-up: If the airline network is very large, or you need to support real-time price updates, how would you optimize?

Quick Answer: This question evaluates understanding of graph algorithms and constrained shortest-path modeling, focusing on reasoning about weighted directed edges, transfer limits, and cost optimization within a travel network; it belongs to the Coding & Algorithms domain.

Related Interview Questions

  • Assign Reviewers from Changed Files - Stripe (medium)
  • Generate Account Email Notifications - Stripe (medium)
  • Calculate Transaction Fees - Stripe (medium)
  • Build an Account Transfer Ledger - Stripe (medium)
  • Implement Validation and String Compression - Stripe (hard)
Stripe logo
Stripe
Feb 11, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
5
0
Loading...

Cheapest Flights Within K Stops

There are n cities (numbered 0..n-1) and a list of flights:

  • flights[i] = [u, v, price] means there is a flight from city u to city v with cost price ( price > 0 ).

Given a source src, destination dst, and integer k, compute: the minimum total price to travel from src to dst with at most k stops (i.e., at most k+1 flight segments).

Output

  • Return the minimum price; if it is impossible to reach the destination within the limit, return -1 .

Constraints / Details

  • Flights are directed edges ( u -> v ).
  • Multiple different flights may connect the same pair of cities.

Follow-up

  • If the airline network is very large ( n , |flights| are large), or you need to support real-time ticket price updates and frequent queries, how would you optimize the overall solution?

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Stripe•More Software Engineer•Stripe Software Engineer•Stripe Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.