Fix LC 787: Correct SPFA time complexity and harden test suite#5799
Open
peizhao1 wants to merge 1 commit intoneetcode-gh:mainfrom
Open
Fix LC 787: Correct SPFA time complexity and harden test suite#5799peizhao1 wants to merge 1 commit intoneetcode-gh:mainfrom
peizhao1 wants to merge 1 commit intoneetcode-gh:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)$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.
Updated the time complexity analysis for the Shortest Path Faster Algorithm (SPFA) solution. The article previously stated the time complexity was
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
shortestdictionary (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 = 5flights = [[0,1,1],[1,2,1],[2,3,1],[3,4,1],[0,2,10]]src = 0dst = 4k = 2Expected Output:
12Resolves #5796, Resolves #5797