Your question is Swap Two Numbers Without Extra Variable. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
ValueMomentum services sometimes transform compact integer buffers in place to reduce temporary allocations. Implement a function that swaps the integers at two positions without using an extra variable, tuple unpacking, or creating another array.
Use the XOR-swap technique. The input list must be modified directly, and the function must return the same list object.
Given an integer list values and valid indices i and j, swap values[i] and values[j] in place. Return values. All list elements are integers, and i and j may refer to the same position.
def swap_without_temp(values, i, j):