We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static int beautifulTriplets(int d, List arr) {
// Write your code here
int[] result ={0};
arr.stream().forEach(v->{
if(arr.contains(v+d)&&arr.contains(v+(2*d))){
result[0]++;
}
});
return result[0];
}
Cookie support is required to access HackerRank
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 →
here is the Java8 code
public static int beautifulTriplets(int d, List arr) { // Write your code here int[] result ={0}; arr.stream().forEach(v->{ if(arr.contains(v+d)&&arr.contains(v+(2*d))){ result[0]++; } });