My issue #Authors #kingmessi #pols_agyi_pols #iceknight1093
Wrong testcases designed or Wrong Question designed
A permutation of length N is an array of length N that contains every integer from
1 to N, in some order.
if the array is not sorted the answer will be always (N+1)
My code
import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner sc=new Scanner(System.in);
int tc=sc.nextInt();
while(tc-->0)
{
int n=sc.nextInt();
int a[]=new int[n];
boolean issorted=true;
a[0]=sc.nextInt();
for(int i=1;i<n;i++)
{
a[i]=sc.nextInt();
if(a[i-1]>a[i])
{
issorted=false;
}
}
if(issorted)
{
System.out.println("0");
}
else
{
System.out.println(n+1);
}
}
}
}
Problem Link: Another Game Practice Coding Problem