Skip to content

Fix LC 787: Correct SPFA time complexity and harden test suite#5799

Open
peizhao1 wants to merge 1 commit intoneetcode-gh:mainfrom
peizhao1:fix-cheapest-flights
Open

Fix LC 787: Correct SPFA time complexity and harden test suite#5799
peizhao1 wants to merge 1 commit intoneetcode-gh:mainfrom
peizhao1:fix-cheapest-flights

Conversation

@peizhao1
Copy link
Copy Markdown

@peizhao1 peizhao1 commented May 8, 2026

  • File(s) Modified: articles/cheapest-flight-path.md
  • Language(s) Used: markdown
  • Submission URL: N/A (Documentation/Article update)

Description

This PR addresses Issues #5796 and #5797 by correcting the time complexity analysis in the written article for LC 787 and providing an additional test case to strengthen backend test coverage.

1. Article Update (#5797)
Updated the time complexity analysis for the Shortest Path Faster Algorithm (SPFA) solution. The article previously stated the time complexity was $O(n \cdot k)$. This has been corrected to $O(m \cdot k)$ (where $m$ is the number of edges/flights), as the algorithm iterates through all edges connected to the current node at each level up to $k$ times.

2. Backend Action Required: Hardening Test Coverage (#5796)
The current backend test suite is missing a test case to catch incorrect Dijkstra implementations. Specifically, solutions that permanently track visited nodes using a shortest dictionary (e.g., if node not in shortest: shortest[node] = w) will incorrectly block valid paths that reach a node with a higher cost but fewer stops.

Please add the following test case to the private execution engine database to properly fail these incorrect submissions:

Input: n = 5
flights = [[0,1,1],[1,2,1],[2,3,1],[3,4,1],[0,2,10]]
src = 0
dst = 4
k = 2

Expected Output: 12

Resolves #5796, Resolves #5797

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug Report for cheapest-flight-path Bug Report for cheapest-flight-path

1 participant