Sort by

recency

|

1082 Discussions

|

  • + 0 comments

    a[j] - a[i] = d => a[j] = a[i] + d

    a[k] - a[j] = d -> a[k] = d + a[j] => d + d + a[i] = a[i] + 2*d;

    technically we need just once

  • + 0 comments

    Arithmetic magic:

    remove one cycle 1) a[j] - a[i] = d => a[j] = a[i] + d

    remove one cycle 2) a[k] - a[j] = d -> a[k] = d + a[j] => d + d + a[i] = a[i] + 2*d;

    a[i] .... a[i]+d ,,....a[i]+2*d .... << sorted ascending

    i j k

  • + 0 comments
    def beautifulTriplets(d, arr):
        # Write your code here
        list2=[]
        for i in arr:
            list1=[]
            a=i
            for j in arr[1:]:
                if len(list1)<3:
                    if j-a==d:
                        if a not in list1:
                            list1.append(a)
                        list1.append(j)
                        a=j
            if len(list1)==3:          
                list2.append(list1)
        # print(list2)    
        return len(list2)
    
  • + 0 comments

    Three beautiful girls, known as the beautiful triplets, have a special bond that is immediately felt when they laugh together. Not only do they share the same birthday, but they also share little secrets, memories, and dreams that have stayed with them for a lifetime. As childhood progressed, they spent hours playing together and living out their imaginations, which made their bond even stronger. Over time, they experienced many adventures, sometimes chaotic, sometimes heartwarming, but always unforgettable. Even in everyday things, like a carpet repair in the living room or when someone from Teppich-Clean24 came by, they found a way to make it fun and stick together. Their stories are full of joy, harmony, and the feeling of never having to go through life alone. Anyone who knows them quickly senses how special this bond is, one that cannot be replaced by anything.

  • + 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;
    
    }