Inverse of an array

i want the approach like how is array inverted. basically i want to get the example of an array before inversion and after inversion

inverting a array mean

if in original array arr[i] is at ith position then
in inverted array i will be present at arr[i] th position

consider this example
5
4
0
2
3
1

4 is at 0st position so in ans Array 0 will be at 4th position
similarly
0 is at 1st position so in ans Array 1 will be at 0th position
2 is at 2st position so in ans Array 2 will be at 2th position
1 is at 4st position so in ans Array 4 will be at 1th position

Sample Output
1 4 2 3 0

i hope now question is clear

Solution

Inverse is Simply swapping the value of the array with the value at that index.

Algo

  1. Create a new Array say narr and original array is arr.
  2. now at the arr[i]th index of narr save the ith value.(previously i is the index and arr[i] is the value bt now arr[i] is the index and i is the value.)
  3. return new array.

refer this code -->

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin>>N;
	int a[N];
	for(int i =0;i<N;i++)
		cin>>a[i];
	int b[N];
	for(int j=0;j<N;j++){
		b[a[j]]=j;
	}
    for(int i=0;i<N;i++){
        cout<<b[i]<<" ";
    }
	return 0;
}

clear thanks for explaining

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

Plz give feedback from above link
It hardly takes a min