human
What is a Python program to find the length of the longest consecutive sequence path given the following:
I am working on the file "03_BinaryTree_DivideConquer.ipynb".
The first task is:
Binary Tree Longest Consecutive Sequence III

It's follow up problem for Binary Tree Longest Consecutive Sequence II
Given a k-ary tree, find the length of the longest consecutive sequence path.
The path could be start and end at any node in the tree
Can you write Python program for it?
assistant
#Here is Python program to find the length of the longest consecutive sequence path.

# Definition for a multi tree node.
# class MultiTreeNode(object):
#     def __init__(self, x):
#         self.val = x
#         children = [] # children is a list of MultiTreeNode

class Solution:
    # @param {MultiTreeNode} root the root of k-ary tree
    # @return {int} the length of the longest consecutive sequence path
    def longestConsecutive3(self, root):
        # Write your code here
        longest, _, _ = self.helper(root)
        return longest
        
        
        
    def helper(self, root):
        if root is None:
            return 0, 0, 0
        
        len, down, up = 0, 0, 0 
        for child in root.children:
            clen, cdown, cup = self.helper(child)
            if child.val + 1 == root.val:
                down = max(down, cdown + 1)
            if child.val - 1 == root.val:
                up = max(up, cup + 1)
            len = max(len, clen)
        
        len = max(len, down + up + 1)
        
        return len, down, up