A distinct path is a sequence of nodes that starts at the root, follows tree edges and contain only distinct values. For example: •The sequence [A, B, D] is a distinct path.
• The sequence [A, B, J] is not a distinct path because it doesn’t follow tree edges.
• The sequence [C,G, I] is not a distinct path because it doesn’t start at the root.
• The sequence [A,C,F] is not a distinct path because it contains the value 3 twice.
Write an (optimal) algorithm that finds the number of nodes in the longest distinct path and write down its space and time complexity. In the example above, the number of such nodes is 3.
Please help with writing an algorithm and/or pseudo code with explanation to understand the problem and solution better.