Detect cycle in a directed graph

Problem Link : Detect cycle in a directed graph | Practice | GeeksforGeeks

Can anyone please help me why I am getting TLE in this code…???

maybe because it’s O(nlogn) :/. this should be O(n)