Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.math.*;
- import java.security.*;
- import java.text.*;
- import java.util.*;
- import java.util.concurrent.*;
- import java.util.regex.*;
- public class Solution {
- // Complete the missingNumbers function below.
- static int[] missingNumbers(int[] arr, int[] brr) {
- int countA[] = new int[10000];
- int countB[] = new int[10000];
- Arrays.sort(arr);
- Arrays.sort(brr);
- int min = brr[0];
- int max = brr[brr.length -1];
- for(int i=0;i<arr.length;i++){
- countA[arr[i]]++;
- }
- for(int i=0;i<brr.length;i++){
- countB[brr[i]]++;
- }
- ArrayList<Integer> ansList = new ArrayList<>();
- for(int i=min;i<=max;i++){
- if(countA[i]<countB[i])
- ansList.add(i);
- }
- int[] ans = ansList.stream().mapToInt(i -> i).toArray();
- return ans;
- }
- private static final Scanner scanner = new Scanner(System.in);
- public static void main(String[] args) throws IOException {
- BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
- int n = scanner.nextInt();
- scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
- int[] arr = new int[n];
- String[] arrItems = scanner.nextLine().split(" ");
- scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
- for (int i = 0; i < n; i++) {
- int arrItem = Integer.parseInt(arrItems[i]);
- arr[i] = arrItem;
- }
- int m = scanner.nextInt();
- scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
- int[] brr = new int[m];
- String[] brrItems = scanner.nextLine().split(" ");
- scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
- for (int i = 0; i < m; i++) {
- int brrItem = Integer.parseInt(brrItems[i]);
- brr[i] = brrItem;
- }
- int[] result = missingNumbers(arr, brr);
- for (int i = 0; i < result.length; i++) {
- bufferedWriter.write(String.valueOf(result[i]));
- if (i != result.length - 1) {
- bufferedWriter.write(" ");
- }
- }
- bufferedWriter.newLine();
- bufferedWriter.close();
- scanner.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement