package hackerrank;

import java.util.Scanner;

public class BeautifulTriplets {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
    }
}

@@ -35,138 +35,1061 @@
 til.
-Scanner;%0A%0Apublic class BeautifulTriplets %7B%0A    public static void main(String%5B%5D args) %7B%0A        Scanner in = new Scanner(System.in
+HashSet;%0Aimport java.util.Scanner;%0Aimport java.util.Set;%0A%0Apublic class BeautifulTriplets %7B%0A    private static int beautifulTriplets(int%5B%5D array, int d) %7B%0A        Set%3CInteger%3E set = new HashSet%3C%3E();%0A        for (int i = 0; i %3C array.length; i++) %7B%0A            set.add(array%5Bi%5D);%0A        %7D%0A        int count = 0;%0A        for (int i = 0; i %3C array.length; i++) %7B%0A            int a = array%5Bi%5D;%0A            boolean found = true;%0A            for (int j = 0; j %3C 2; j++) %7B%0A                a = a + d;%0A                if (!set.contains(a)) %7B%0A                    found = false;%0A                    break;%0A                %7D%0A            %7D%0A            if (found) %7B%0A                count++;%0A            %7D%0A        %7D%0A        return count;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Scanner in = new Scanner(System.in);%0A        int n = in.nextInt();%0A        int d = in.nextInt();%0A        int%5B%5D array = new int%5Bn%5D;%0A        for (int i = 0; i %3C n; i++) %7B%0A            array%5Bi%5D = in.nextInt();%0A        %7D%0A        System.out.println(beautifulTriplets(array, d)
 );%0A 

Solve Beautiful Triplets