feat: add gas station greedy algorithm#1008
Closed
AliAlimohammadi wants to merge 1 commit intoTheAlgorithms:masterfrom
Closed
feat: add gas station greedy algorithm#1008AliAlimohammadi wants to merge 1 commit intoTheAlgorithms:masterfrom
AliAlimohammadi wants to merge 1 commit intoTheAlgorithms:masterfrom
Conversation
Contributor
Author
|
@siriak, this is ready to be merged. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1008 +/- ##
==========================================
+ Coverage 96.02% 96.03% +0.01%
==========================================
Files 377 378 +1
Lines 27217 27301 +84
==========================================
+ Hits 26135 26219 +84
Misses 1082 1082 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Member
|
We are not adding LeetCode problems |
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 adds a solution to the Gas Station problem (LeetCode No. 134) to the
greedymodule.Problem Statement
Given
ngas stations along a circular route where:ihasgas[i]amount of gascost[i]gas to travel from stationito stationi+1-1if no solution existsAlgorithm
The solution uses a greedy approach with optimal time complexity:
Why this works: If we can't reach station
ifrom stationj, we also can't reachifrom any station betweenjandi, so we can skip all intermediate stations.Changes Made
src/greedy/gas_station.rswith complete implementationsrc/greedy/mod.rsto include the new moduleDIRECTORY.mdwith the new algorithmTesting
All tests pass successfully:
cargo test gas_stationTests cover:
Complexity
Code Quality
cargo fmtcargo clippy)Type of Change
Checklist
DIRECTORY.mdReferences