Loop to maintain the last occurrence of the 1 in the string
for i in range ( n ) : NEW_LINE INDENT if ( s [ i ] == '1' ) : NEW_LINE INDENT arr [ i ] = i NEW_LINE last_indexof1 = i NEW_LINE DEDENT else : NEW_LINE INDENT arr [ i ] = last_indexof1 NEW_LINE DEDENT DEDENT