Help me in solving MAKE_IT_ONE problem

My issue

can any explain the logic used to solve this problem??

My code

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		while(t-->0)
		{
		    int l=sc.nextInt();
		    int r=sc.nextInt();
		    int n=r-l+1;
		    int a[]=new int[n];
		    int x=l;
		    for(int i=0;i<n;++)
		    a[i]=x++;
		    int b[]=new int[n];
		    b=Collections.reverse(Arrays.asList(a)); 
		}
	}
}

Problem Link: Make It One Practice Coding Problem - CodeChef

I solved the problem as follows:
If L and R are both even, no ordering exists. This is because even numbers in A have to be matched to odd numbers in B, and there are more even numbers than odd numbers in the range [ L, R ].
For all other cases, it is possible to construct B. First B = \{ L, L+1, ... R \}. Then adjacent elements in B are swapped to get B = \{ L+1, L, L+3, L+2, ... \} so that each element i is matched with i-1 or i+1, ensuring gcd to be 1. If total number of elements (R-L+1) is odd, then last element R is matched with R. As R-2 in A is matched with R-1 in B, elements R and R-1 can be swapped in B to get a valid B.