TikTok Interview Question

How to detect if this graph is a tree?