-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay 1. Fitting the array
81 lines (55 loc) · 1.84 KB
/
Day 1. Fitting the array
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Question of the day: https://practice.geeksforgeeks.org/problems/fitting-the-array1514/1
//{ Driver Code Starts
//Initial Template for Java
//Initial Template for Java
/*package whatever //do not write package name here */
import java.io.*;
import java.util.*;
class Day1 {
// Driver code
public static void main (String[] args) throws IOException{
// Taking input using buffered reader
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int testcases = Integer.parseInt(br.readLine());
// looping through all testcases
while(testcases-- > 0){
String line = br.readLine();
String[] element = line.trim().split("\\s+");
int N = Integer.parseInt(element[0]);
int arr [] = new int[N];
line = br.readLine();
String[] elements = line.trim().split("\\s+");
for(int i = 0;i<N;i++){
arr[i] = Integer.parseInt(elements[i]);
}
int brr [] = new int[N];
line = br.readLine();
String[] elem = line.trim().split("\\s+");
for(int i = 0;i<N;i++){
brr[i] = Integer.parseInt(elem[i]);
}
Solution obj = new Solution();
boolean ans = obj.isFit(arr, brr, N);
if(ans == true)
System.out.println("YES");
else
System.out.println("NO");
}
}
}
// } Driver Code Ends
//User function Template for Java
class Solution{
// Function for finding maximum and value pair
public static boolean isFit (int arr[], int brr[], int n) {
int c=0;
Arrays.sort(arr);
Arrays.sort(brr);
for(int i=0; i<n; i++){
if(arr[i]> brr[i]){
return false;
}
}
return true;
}
}