Clicky

Codility PermCheck test 100% score

September 17, 2014

Solution to Codility PermCheck Problem at:

[https://codility.com/c/intro/demoJH2RM2-UZ8](https://codility.com/c/intro/demoJH2RM2-UZ8)
class Solution {

public static void main(String[] args) {
int A[] = {4, 1, 3, 2};
//int A[] = {4, 4, 3, 2};
//int A[] = {4, 3, 2};
//int A[] = {};
//int A[] = {1000000000, 3, 2};
//int A[] = {1000000000, 1000000001, 1000000002};
//int A[] = new int[100000];
System.out.println(solution(A));
}

public static int solution(int[] A) {  
 int result = 0;  
 int size = A.length;  
 int[] B = new int[A.length];  
 if(size == 0)  
  return 0;  
 for(int i=0; i<A.length; i++){  
  if(A[i]>size)  
   return result;  
  if(A[i]<1)  
   return result;  
  if(B[A[i]-1] == -1)  
   return result;  
  else   
   B[A[i]-1] = -1;  
 }  
 return 1;  
}  

}