You are viewing a single comment's thread. Return to all comments →
there is no need to 'continue' if you are using a sorted array.
Here is a working code:
Arrays.sort(arr); int count = 0; for(int i=0; i < arr.length - 1;i++) { for (int j=i; j < arr.length;j++) { if (arr[j] - arr[i] > k) { break; } else if (arr[j] - arr[i] == k) { count++; } } } return count;
Seems like cookies are disabled on this browser, please enable them to open this website
Pairs
You are viewing a single comment's thread. Return to all comments →
there is no need to 'continue' if you are using a sorted array.
Here is a working code: