-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathC - Omkar and Baseball.cpp
51 lines (48 loc) · 976 Bytes
/
C - Omkar and Baseball.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#define ll long long
#include<bits/stdc++.h>
using namespace std;
int main()
{
ll T;
cin>>T;
while(T--)
{
ll n;
cin >> n;
ll arr[n], i, start = 0, end = 0, ans = 0;
for(i=0; i<n; i++)
cin >> arr[i];
for(i=0; i<n; i++)
{
if(arr[i]!= i+1){
start = i;
break;
}
}
for(i=n-1; i>=0; i--)
{
if(arr[i] != i+1){
end = i;
break;
}
}
if(start == 0 && end == 0)
cout <<'0'<< endl;
else
{
for(i=start; i<end; i++)
{
if(arr[i] == i+1)
{
ans = 2;
break;
}
}
if(ans == 0)
cout << '1' << endl;
else
cout << ans << endl;
}
}
return 0;
}