You are viewing a single comment's thread. Return to all comments →
public static int beautifulTriplets(int d, List<Integer> arr) { int tripletcount = 0; for(int i = 0; i < arr.size(); i++) { for(int j=i+1; j< arr.size(); j++) { if(arr.get(j) - arr.get(i) == d && findThirdNumber(arr, j, d, arr.get(j))) { tripletcount++; break; } } } return tripletcount; } private static boolean findThirdNumber(List<Integer> arr, int j, int d, int jval) { for(int k = j+1; k < arr.size(); k++) { if(arr.get(k) - jval == d) return true; } return false; }
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 →