Maximum length sub - sequence of ( 0. . 1. .0 . .1 . . )
for i in range ( 1 , n ) : NEW_LINE INDENT if arr [ i ] == 1 : NEW_LINE INDENT dp [ 3 ] [ i ] = max ( [ dp [ 3 ] [ i - 1 ] + 1 , dp [ 2 ] [ i - 1 ] + 1 , dp [ 1 ] [ i - 1 ] + 1 , dp [ 0 ] [ i - 1 ] + 1 ] ) NEW_LINE DEDENT else : NEW_LINE INDENT dp [ 3 ] [ i ] = dp [ 3 ] [ i - 1 ] NEW_LINE DEDENT DEDENT