Trying to solve codility lessons for practice and working on [this](https://codility.com/programmers/task/perm_check).

Written my code in Java and tested the code on a wide range of inputs, however the code fails for extreme\_min\_max, single and double in the codility test results.

Assumption given:

N is an integer within the range `[1..100,000]`.  

Each element of array A is an integer within the range `[1..1,000,000,000]`.

Explanation of my code:  

1. Sort the given array.  

2. Iterate over each element in the array to find the difference between every consecutive pair. If the difference is not 1, Then its not a perm hence return 0. In case there is only one element in the array, return 1.

Can anyone please help me find out the bug(s) in my code?

My code:

```
public int solution(int[] A)
{
    if(A.length == 1)
        return 1;

    Arrays.sort(A);
    for (int i = 0; i < A.length-1; i++)
    {
        long diff = Math.abs(A[i] - A[i+1]);
        if(diff!=1)
            return 0;
    }
    return 1;
}

```