Given an arbitrary array of size n
, I'd like to reorganize the elements of the array based on the array's discrete indices.
Python example:
# Unique array of size n
[ "a", "b", "c", "d", "e", ... <n> ]
# Indices of array
[ 0, 1, 2, 3, 4, ... <index_of_n> ]
# Desired re-organization function 'indexMove'
indexMove(
[ "a", "b", "c", "d", "e", ... <n> ],
[ <index_of_n>, 4, 0, 2, 3, ... 1 ]
)
# Desired output from indexMove operation
[ <n>, "e", "a", "c", "d", ... "b" ]
What is the fastest way to perform this operation (achieving the smallest time complexity)?