You are viewing a single comment's thread. Return to all comments →
C# Solution
public static int beautifulTriplets(int d, List<int> arr) { int triplets = 0; bool firstDifference, secondDifference; for(int i = 0; i < arr.Count; i++) { secondDifference = false; firstDifference = false; for(int j = i + 1; j <= arr.Count - 1; j++) { if(arr[j] - arr[i] == d && arr[j] != arr[i]) firstDifference = true; if(firstDifference && arr[j] - arr[i] == 2*d) secondDifference = true; if(secondDifference && firstDifference) { triplets++; break; } } } return triplets; }
Seems like cookies are disabled on this browser, please enable them to open this website
Beautiful Triplets
You are viewing a single comment's thread. Return to all comments →
C# Solution