Filling left and right values using same values of previous ( or next
for i in range ( 1 , n ) : NEW_LINE INDENT if templeHeight [ i - 1 ] < templeHeight [ i ] : NEW_LINE INDENT chainSize [ i ] . L = chainSize [ i - 1 ] . L + 1 NEW_LINE DEDENT else : NEW_LINE INDENT chainSize [ i ] . L = 1 NEW_LINE DEDENT DEDENT for i in range ( n - 2 , - 1 , - 1 ) : NEW_LINE INDENT if templeHeight [ i + 1 ] < templeHeight [ i ] : NEW_LINE INDENT chainSize [ i ] . R = chainSize [ i + 1 ] . R + 1 NEW_LINE DEDENT else : NEW_LINE INDENT chainSize [ i ] . R = 1 NEW_LINE DEDENT DEDENT