Sunday common C++ interview problem: Longest cycle in a graph. Given a directed graph as std::vector<int>, where the value at index i represents the destination of an outgoing edge from i (-1 is used to represent no outgoing edges), determine the size of the longest cycle in the graph. Solve it yourself: https://lnkd.in/etuXg4Jd Solution: https://lnkd.in/ekdv5U6C #cpp #cplusplus #coding #programming #dailybiteofcpp
Dfs or bfs
Hi Simon. Do you see any problem with this solution? https://compiler-explorer.com/z/efE7dTes4 I find it more compact and intuitive, but it probably is because it was the one I came up with :), or perhaps it has another issue why it wouldn't work on some cases. It is also O(n) if I'm not missing anything.