Finding and returning a loopy path in a directed graph
You should use an array to check if you have already visited a node and not visits.contains(node), it would give you the answer in constant time instead of linear time.

The overall complexity of your algorithm is exponential. For instance, if you run your algorithm on this graph:

0 -&gt; 1, 2, ..., n
1 -&gt; 2, ..., n
...


where there are n nodes and there are edges from i to j iff i&lt;j then the node i will be explored 2^i times.

Again you can solve this problem using an array (one array for all nodes) to ensure that each node is explored at most one time.