Professional Documents
Culture Documents
REG NO : 19BCD7246
SLOT : L27 + L28 + L31 + L32
ASSIGNMENT NUMBER : 05
import java.util.*;
class RabbitToHole{
public static void main(String[]args){
Scanner scan = new Scanner(System.in);
int t = scan.nextInt(); //no.of testcases
while(t-->0){
int n = scan.nextInt(); //no.of rabbits and holes
int A[] = new int[n]; //no.of rabbits
int B[] = new int[n]; //no.of holes
for(int i=0;i<n;i++){
A[i]=scan.nextInt();
}
for(int i=0;i<n;i++){
B[i]=scan.nextInt();
}
System.out.println(assign(A,B));
}
scan.close();
}
static int assign(int A[], int B[]){
int n = A.length;
int max_val=0;
Arrays.sort(A);
Arrays.sort(B);
for(int i=0;i<n;i++){
if(max_val<Math.abs(A[i]-B[i])){
max_val=Math.abs(A[i]-B[i]);
}
}
return Math.abs(max_val);
}
}
OUTPUT
CODE
import java.util.*;
class SwapLL{
public static void main(String[]args){
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();//no.of test cases
while(t-->0){
LinkedList<Integer> ll = new LinkedList<Integer>();
LinkedList<Integer> ll2 = new LinkedList<Integer>();
LinkedList<Integer> ll3 = new LinkedList<Integer>();
int n = scan.nextInt(); // no.of nodes in linkedlist
for(int i=0;i<n;i++){
ll.add(scan.nextInt());
}
for(int i:ll){
ll3.add(i);
}
for(int i=0;i<n;i++){
ll2.add(ll.get(n-i-1));
}