Git Product home page Git Product logo

assignment's Introduction

Longest Path in a Weighted Directed Acyclic Graph (DAG)

Instructions

  1. Clone this repository to your local machine.
  2. Implement the function(s) in main.py.
  3. Ensure your code passes all the tests in test_main.py.
  4. Commit and push your changes to your repository.
  5. Submit the link to your repository.

Problem Statement

You are given a Directed Acyclic Graph (DAG) with n nodes, numbered from 0 to n-1. The graph is represented as an adjacency list where graph[i] is a list of tuples (j, w), representing an edge from node i to node j with weight w. Your task is to find the longest path in the graph starting from any node.

  • Function Signature:
    def longest_path(graph: list) -> int:

Parameters: graph (list): A list of lists, where graph[i] contains tuples (j, w) representing an edge from node i to node j with weight w.

Returns:
    int: The length of the longest path in the graph.

#Example

Input:

graph = [ [(1, 3), (2, 2)], [(3, 4)], [(3, 1)], [] ]

Output:

7

Explanation: The longest path is from node 0 -> node 1 -> node 3 with a total weight of 3 + 4 = 7.

assignment's People

Contributors

scoreme1 avatar abhavgoel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.