AlgoFrames

Count distinct encodings

Standard · Multiple choice · about 4 min

Someone saves a tree as its pre-order values only, with no # markers: "1,2,3". How many different binary trees give exactly this string?

Example 1

Input:

1,2,3

Output:

5

This tree is one of them.

Constraints

  • Count trees with exactly 3 nodes whose pre-order is 1, 2, 3.

Learn the idea first: Serialization and construction, a visual lesson.

More Serialization and construction problems