LUCKYPAIR (Lucky Pair) Editorial

LUCKYPAIR (Lucky Pair)

Problem link -LINK
Author- Aagam Jain
Tester - Aman Gupta

Difficulty : Simple
Problem Tag : Implementation , Iower-Upper bound

Problem :
Aryan goes to buy candles from the market where he bought N candles. A pair of candles is lucky if the absolute difference of their height is strictly greater than l and less than or equal to r.
You are given N candles and Hi represents the height of each candle. Now, you have to tell the total number of lucky pairs of candles.

Explanation :
Simple brute force approach use two for loops to find the number of candles present in the upper and lower bound limit l and r.

My Solution :

import java.util.*;
import java.lang.*;
import java.io.*;
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc=new Scanner(System.in);
		int tc=sc.nextInt();
		while(tc-->0)
		{
		    int n=sc.nextInt();
		    int l=sc.nextInt();
		    int r=sc.nextInt();
		    int arr[]=new int[n];
		    for(int i=0;i<n;i++)
            arr[i]=sc.nextInt();
            int count=0;
            for(int i=0;i<n-1;i++)
            {
            for(int j=i+1;j<n;j++)
            {
               if(Math.abs(arr[i]-arr[j])>l && Math.abs(arr[i]-arr[j])<=r)
                  {count++;}
            }
            }
            System.out.println(count);
       }
	}
}