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.
importjava.io.*;importjava.util.*;publicclassSolution{publicstaticintbeautifulTripletsCount(ArrayList<Integer>e,intn,intd){intcount=0;for(Integerv:e){if(e.contains((v+d))&&e.contains((v+2*d)))count++;}returncount;}publicstaticvoidmain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */Scannerin=newScanner(System.in);intn=in.nextInt(),d=in.nextInt();ArrayList<Integer>elements=newArrayList<>();for(inti=0;i<n;i++){elements.add(in.nextInt());}System.out.println(beautifulTripletsCount(elements,n,d));}}
Beautiful Triplets
You are viewing a single comment's thread. Return to all comments →
My Solution in Java