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.
Beautiful Triplets
Beautiful Triplets
Sort by
recency
|
1044 Discussions
|
Please Login in order to post a comment
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]++; } });
def beautifulTriplets(d, arr): counter = 0 n = len(arr) for i in range(n): for j in range(i, n): if arr[j]-arr[i] == d: for k in range(j, n): if arr[k]-arr[j] == d: counter += 1 return counter
int beautifulTriplets(int d, vector arr) { unordered_set t; unordered_set :: iterator it; int count = 0;
} why the test case 10 is failing 10 3 1, 6, 7, 7, 8, 10 , 12, 13, 14, 19 expected answer is 2 but only 1 possible triplet can be found here...
Here is my O(n) c++ solution, you can watch the implementation here : https://youtu.be/vLD3N79nLSE