Instead of finding the minimum each time, we could replace `len` with the remaining count of the tree (if it's less).