Šimon Tóth’s Post

View profile for Šimon Tóth

C++ Educational Content Creator | 20 years of Software Engineering experience distilled into digestible daily posts

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

  • diagram

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.

  • No alternative text description for this image
Like
Reply
See more comments

To view or add a comment, sign in

Explore content categories