You are viewing a single comment's thread. Return to all comments →
Using Brute Force C# solution
public static int pairs(int k, List<int> arr) { int count=0; arr.Sort(); for(int i=0;i<arr.Count;i++){ for(int j=i+1;j<arr.Count;j++){ if(Math.Abs(arr[i]-arr[j])==k) count++; else if(Math.Abs(arr[i]-arr[j])>k) break; } } 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 →
Using Brute Force C# solution