Hint for duplicate names

If you follow the templates, you'll want an accumulator for all the file names you've ever seen while looking through the tree. You can stop the entire algorithm if and when you find a duplicate.

As another approach that has some strong similarities, flatten the tree first into a big list, and then look for duplicates in the result. That way, you get to ignore the tree structure.

Which is best?

In short, it isn't clear which is better.