Sort by

recency

|

1078 Discussions

|

  • + 0 comments

    c++

    int beautifulTriplets(int d, vector<int> arr) {
        
        unordered_set<int> s(arr.begin(), arr.end()); 
        int c = 0;
    
        for (size_t i = 0; i < arr.size(); i++) {
            if (s.count(arr[i]) && 
                s.count(arr[i] + d) && 
                s.count(arr[i] + 2 * d)) 
            {
                c++;
            }
        }
        return c;
    
    }
    
  • + 0 comments

    **Shortest Python Solution **

        s = set(arr)
        c = 0
        for i in range(len(arr)-2):
            if arr[i] in s and arr[i]+d in s and arr[i]+(d*2) in s :
                c += 1
        return c
    
  • + 0 comments
    def beautifulTriplets(d, arr):
        # Write your code here
        c = 0 
        for i in range(len(arr)-2):
            x = [arr[i],arr[i]+d,arr[i]+(d*2)]
            y = [True if j in arr else False for j in x ]
            if all(y):
                c += 1
        return c
    
  • + 0 comments
    def beautifulTriplets(d, arr):
        # Write your code here
        
        count = 0
        lookup = set(arr)
        
        for i in arr:
            num2 = i + d
            num3 = num2 + d
            
            if num2 in lookup and num3 in lookup:
                count += 1
                
        return count
    
  • + 0 comments

    Very Simple method with Include in Javascript

    function beautifulTriplets(d, arr) { let count =0 for(let i = 0;i

    }