How to update key after swapping

how to update key after swapping

hello @arti07411
store index of each numbers in map.
update that map while performing swap operation.
pls refer this code->