Find the smallest digit on right side of ith digit which is greater than num [ i ] up to index 'mid
' NEW_LINE INDENT smallest = i + 1 NEW_LINE j = i + 2 NEW_LINE while j <= mid : NEW_LINE INDENT if ( num [ j ] > num [ i ] and num [ j ] < num [ smallest ] ) : NEW_LINE INDENT smallest = j NEW_LINE DEDENT j = j + 1 NEW_LINE DEDENT DEDENT