I believe that the output shown in the question should 31420
Output in example
Hey, actually it’s inverse of an array not reverse. Had it been reverse then your output is correct…
Inverse is Simply swapping the value of the array with the value at that index.
Algo
- Create a new Array say narr and original array is arr.
- 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.)
- 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;
}
Hey, i hope it’s clear now. If still there is anything do let me know…