Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
First try to understand the problem carefully and then take some example and solve it on a paper.
Can you interpret the given input as a graph? Which graph traversal technique is suitable here?
Can we use some space to avoid redundant function calls?