#include
using namespace std;
int main() {
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
cout<<a[0]<<" ā;
for(int i=n-1;i>0;iā)
{
cout<<a[i]<<ā ";
}
return 0;
}
#include
using namespace std;
int main() {
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
cout<<a[0]<<" ā;
for(int i=n-1;i>0;iā)
{
cout<<a[i]<<ā ";
}
return 0;
}
reversing and inversing array are 2 different things
here you have to inverse, not reverse
Inverse is Simply swapping the value of the array with the value at that index.
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;
}
but this solution only works if values array elements contains all the index values. Suppose if a[i]=100 and size of array is 5 then this solution will fail
if you are finding inverse of array then this will never happen
array element must be from 0 to n-1
kindly check again it is passing all testcases