Traverse ll ancestors and update result if any parent node gives smaller distance
for i in reversed ( range ( 0 , index ) ) : NEW_LINE INDENT res = min ( res , index - i + closestDown ( ancestors [ i ] ) ) NEW_LINE DEDENT return res NEW_LINE