Here we are calculating the actual position of k in the array .
for i in range ( n ) : NEW_LINE INDENT if ( arr [ i ] == k ) : NEW_LINE INDENT pos = i NEW_LINE break NEW_LINE DEDENT DEDENT left = 0 NEW_LINE right = n - 1 NEW_LINE