You are viewing a single comment's thread. Return to all comments →
import java.util.*; public class Solution { public static void main(String[] args) { Scanner inr = new Scanner(System.in); int n = inr.nextInt(), k = inr.nextInt(); int[] num = new int[n]; for (int i = 0; i < n; i++) num[i] = inr.nextInt(); Arrays.sort(num); int count = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { int diff = num[j] - num[i]; if (diff == k) count++; if (diff > k) break; } } System.out.println(count); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Pairs
You are viewing a single comment's thread. Return to all comments →