Skip to content

feat: add minTime solutions in Python, C++, and Go for LC problem #3604 #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2025

Conversation

Speccy-Rom
Copy link
Owner

@Speccy-Rom Speccy-Rom commented Jul 23, 2025

Summary by Sourcery

Introduce new solutions for "Minimum Time to Reach Destination in Directed Graph" (LeetCode 3604) in Python, C++, and Go, and update documentation to reflect these additions

New Features:

  • Add Python implementation of the minTime function using a priority queue for LC problem 3604
  • Add C++ implementation of the minTime function with a min-heap for LC problem 3604
  • Add Go implementation of the minTime function with a priority queue for LC problem 3604

Documentation:

  • Update README and README_EN to include the new Python, C++, and Go solutions

Copy link

sourcery-ai bot commented Jul 23, 2025

Reviewer's Guide

This PR introduces new implementations of the minTime function for LC problem doocs#3604 in Python, C++, and Go, each leveraging a priority-queue-based Dijkstra variant that respects edge time windows to compute the minimum travel time or return -1 if unreachable.

Class diagram for Go solution: minTime and supporting types

classDiagram
    class Item {
        int value
        int priority
        int index
    }
    class PriorityQueue {
        +Len() int
        +Less(i, j int) bool
        +Swap(i, j int)
        +Push(x any)
        +Pop() any
    }
    class minTime {
        +minTime(n int, edges [][]int) int
    }
    minTime ..> PriorityQueue : uses
    PriorityQueue o-- Item : holds
Loading

Class diagram for C++ solution: Solution class

classDiagram
    class Solution {
        - vector<vector<vector<int>>> adj
        - vector<int> sol
        - priority_queue<pair<int,int>, vector<pair<int,int>>, greater<>> pq
        - void pushNeighbours(int node, int curr)
        + int minTime(int n, vector<vector<int>>& edges)
    }
Loading

Class diagram for Python solution: Solution class

classDiagram
    class Solution {
        +minTime(n: int, edges: List[List[int]]) -> int
    }
Loading

File-Level Changes

Change Details Files
Implement Python version of minTime with time-constrained Dijkstra
  • Initialize minReachTime array and adjacency lists from edge inputs
  • Use a min-heap to process nodes by current reach time
  • Calculate wait time against edge start/end and update reach times accordingly
solution/3600-3699/3604.Minimum Time to Reach Destination in Directed Graph/README.md
solution/3600-3699/3604.Minimum Time to Reach Destination in Directed Graph/README_EN.md
solution/3600-3699/3604.Minimum Time to Reach Destination in Directed Graph/Solution.py
Implement C++ version of minTime with helper function and priority queue
  • Build nested vector adjacency list and sol vector initialized to INT_MAX
  • Define pushNeighbours helper to evaluate and push valid edges
  • Use a min-oriented priority_queue for earliest-time extraction
  • Add atexit hooks to output runtime and memory placeholders
solution/3600-3699/3604.Minimum Time to Reach Destination in Directed Graph/README.md
solution/3600-3699/3604.Minimum Time to Reach Destination in Directed Graph/README_EN.md
solution/3600-3699/3604.Minimum Time to Reach Destination in Directed Graph/Solution.cpp
Implement Go version of minTime with custom heap.Interface types
  • Construct graph as slice of [3]int for each edge (v, start, end)
  • Maintain dist slice with -1 as unreachable sentinel and initialize start node
  • Define Item and PriorityQueue types implementing heap.Interface
  • Perform Dijkstra-like loop with wait time calculation and priority queue updates
solution/3600-3699/3604.Minimum Time to Reach Destination in Directed Graph/README.md
solution/3600-3699/3604.Minimum Time to Reach Destination in Directed Graph/README_EN.md
solution/3600-3699/3604.Minimum Time to Reach Destination in Directed Graph/Solution.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@Speccy-Rom Speccy-Rom merged commit 3a83873 into main Jul 23, 2025
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Speccy-Rom - I've reviewed your changes - here's some feedback:

  • Add the required imports (List, inf from math, and heapq) to the Python snippet so it’s runnable as-is.
  • The C++ solver’s atexit hook writing to display_runtime.txt/display_memory.txt seems unrelated to the algorithm and could be removed or documented separately.
  • You currently have two Go implementations (in the README and Solution.go); consider consolidating into a single source to reduce duplication.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Add the required imports (List, inf from math, and heapq) to the Python snippet so it’s runnable as-is.
- The C++ solver’s atexit hook writing to display_runtime.txt/display_memory.txt seems unrelated to the algorithm and could be removed or documented separately.
- You currently have two Go implementations (in the README and Solution.go); consider consolidating into a single source to reduce duplication.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

1 participant