educative.io

The solution is only counted correctly if you do pre-order traversal

Hello,

I believe the solution returns correct if you do pre-order traversal (find all words stored in a trie exercise), however if you do post-order traversal and get the correct answer it still says it is wrong.

Firstly, am I correct in observing this? Second, could it be changed such that it also allows the post-order traversal answer to be counted as correct?

Yours sincerely,

Riaan Zoetmulder

Hello @Riaan_Zoetmulder

Indeed, you are correct. When attempting to solve the problem using post-order traversal, the tests do not pass, and for valid reasons.

According to the problem statement, the expected output should be “A sorted list of all the words stored in a trie.” However, when implementing the post-order traversal method, the resulting output would resemble something like “'abc', 'answer', 'any', 'a', 'bye', 'by,” which is not sorted.

As a result, the test fails due to the lack of sorted order in the output.

I hope this will help.
Happy Learning

1 Like