public static int findPairs(int[] arr, int k){
        Arrays.sort(arr);
        int start = 0, end = 0;
        int len = arr.length;
        int count = 0;
        while(end < len){
            if(arr[end] - arr[start] > k){
                start++;
            }else if(arr[end] - arr[start] < k){
                end++;
            }else{
                count++;
                start++;
                end++;
            }
        }
        return count;
    }