• + 0 comments

    Hi, I'm having an issue to run the code i did in this exercise. I tested on my machine and it worked as expected. But for some reason, the test here does not output any value. Am I doing something wrong?

    def topView(root):
        left_wing = ''
        right_wing = ''
        if(root.left is not None):
            left_wing = topView(root.left)
        if(root.right is not None):
            right_wing = topView(root.right)
            
        ''' return value if is a leaf '''
        if((root.left is None) & (root.right is None)):
            return str(root.info)
        ''' If it has only the right side '''
        if(left_wing == ''):
            return str(root.info) +' '+ right_wing
        ''' If it has only the left side '''
        if(right_wing == ''):
            return str(root.info) +' '+ left_wing
        ''' Else then check between both wings'''
        rw_max = int((right_wing.split(' '))[-1])
        lw_max = int((left_wing.split(' '))[-1])
        
        if(rw_max>=lw_max):
            return str(root.info) +' '+ right_wing
        else:
            return str(root.info) +' '+ left_wing