Traverse the string to find the first and last occurrences of '1
' NEW_LINE INDENT for i in range ( len ( str ) ) : NEW_LINE INDENT if ( str [ i ] == '1' ) : NEW_LINE INDENT if ( firstOne == - 1 ) : NEW_LINE INDENT firstOne = i NEW_LINE DEDENT lastOne = i NEW_LINE DEDENT DEDENT if ( ( firstOne == - 1 ) or ( firstOne == lastOne ) ) : NEW_LINE INDENT print ( 0 ) NEW_LINE return NEW_LINE DEDENT DEDENT