MAKPERM giving WA

my code is giving WA but i am not getting what is the error as all test cases are satisfied made by me

the link to the problem is

and my solution is

Blockquote
#include<bits/stdc++.h>
using namespace std;

int main()
{

long long int t;
cin>>t;
while(t--)
{
     long long int n;
     cin>>n;

     long long int arr[n];
     for(long long int i=0;i<n;i++)
     {
        cin>>arr[i];
     }
    
       sort(arr,arr+n);
       long long int count=0;
     for(long long int i=0;i<n;i++)
     {
         if(arr[i]!=i+1)
          count++;
     }
     
     cout<<count<<endl;
} 

}

Try this test case :-
1
4
2 3 4 5

Answer should be 1 move (5 -> 1)
but your code prints 4.

2 Likes

Thanks, @codeguptaji for support can you provide more test cases btw

actually your logic is wrong…
This is my code :-

cin >> n;
vector a(n);
//read vector
unordered_map<int,int,custom_hash>m;
for(auto x : a)
m[x] = 1;
for(i=1;i<=n;i++)
if(m[i] == 0)
sum++;
cout << sum << endl;

@codeguptaji I have done it I was doing some basic mistake but I want to know how to think a correct approach just by given test cases as what approach I thought I just applied at first but after your test case I realized how to think for test cases and mistakes that my code have