My issue
Can someone read my code and tell me that how can I avoid duplicate output like(2,6) and (6,2).
My code
import java.util.Scanner;
import java.lang.Math;
import java.io.*;
class Codechef
{
public static void main(String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
int n = sc.nextInt();
int a = 0, b = 0, c = 0, count = 0;
int arr[] = new int[n];
for (int j = 0; j < n; j++) {
arr[j] = sc.nextInt();
}
for (int x = 0; x < n - 1; x++) {
for (int k = x + 1; k < n; k++) {
a = Math.abs(arr[x] - arr[k]);
b = arr[x] + arr[k];
c = arr[x] * arr[k];
int p = Math.abs(b - a);
int q = Math.abs(c - b);
if (p == q) {
count = count + 1;
}
}
}
System.out.println(count);
}
}
}
Problem Link: Freedom Practice Coding Problem - CodeChef