23. Length of Longest Cycle in a Graph
β GFG solution to the Length of Longest Cycle in a Graph problem: find the longest cycle in a directed functional graph using iterative timestamp traversal. π
π§© Problem Description
π Examples
Example 1
Input: V = 7, edges[][] = [[0,5],[1,0],[2,4],[3,1],[4,6],[5,6],[6,3]]
Output: 5
Explanation: The longest cycle is 0 β 5 β 6 β 3 β 1 β 0, which has length 5.Example 2
Input: V = 8, edges[][] = [[0,1],[1,2],[2,3],[3,0],[4,1],[5,4],[6,2],[7,6]]
Output: 4
Explanation: The longest cycle is 0 β 1 β 2 β 3 β 0, which has length 4.π Constraints
β
My Approach
Timestamp Traversal (Iterative)
π Time and Auxiliary Space Complexity
π§βπ» Code (C++)
β Code (Java)
π Code (Python)
π§ Contribution and Support
πVisitor Count
Last updated