Implement an efficient algorithm to detect a cycle in a directed graph and explain how you would optimize it for massive datasets.
You are practicing as a guest. Sign up free to get your answer graded with AI feedback. Your draft stays right here.