Description
#9 will result in an MVP form of AnyN
that uses Range()
. A better implementation is to reuse as much of an existing tree as possible. The basic idea is to start building a new tree out of an old tree, Taking enough children till you exceed the desired count. Then take the last subtree that exceeded the limit and recursively call last_subtree.anyN(n - sum(other subtree counts))
.
An efficient node count #20 would speed this up dramatically.
My initial thinking was to also look for optimal choices of subtrees to get as close as possible to n then choosing a small subtree to fill in the remainder. However, this will be ineffective because hash trees are extremely well balanced. Nothing will be gained by playing these sorts of games.