I think the tree/trie approach implementation-wise would be hard to check the differences and skip levels. With this size input, the O(N2) was totally fine and ran instantaneously for me.
As I said to @tiago
the purpose for this exercise is just fun.
I think that it would be hard implementation-wise but I was thinking a DFS that backtracked whenever the second different character was found. It would be hard keeping track of the number of different characters found for a given node but not impossible.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I think the tree/trie approach implementation-wise would be hard to check the differences and skip levels. With this size input, the O(N2) was totally fine and ran instantaneously for me.
As I said to @tiago the purpose for this exercise is just fun.
I think that it would be hard implementation-wise but I was thinking a DFS that backtracked whenever the second different character was found. It would be hard keeping track of the number of different characters found for a given node but not impossible.