fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. Scanner sc = new Scanner(System.in);
  14. int n = sc.nextInt();
  15. int arr1[] = new int[n];
  16.  
  17. HashSet<Integer> hash = new HashSet<>();
  18.  
  19. for(int i=0;i<n;i++){
  20. int val = sc.nextInt();
  21. hash.add(val);
  22. }
  23.  
  24. int m = sc.nextInt();
  25. int arr2[] = new int[m];
  26.  
  27. for(int i=0;i<m;i++){
  28. int val = sc.nextInt();
  29. if(!hash.contains(val)){
  30. System.out.println("arr2 is not a subset of arr1");
  31. return;
  32. }
  33. }
  34.  
  35. System.out.println("arr2 is a subset of arr1");
  36.  
  37. }
  38. }
Success #stdin #stdout 0.12s 54512KB
stdin
5 
2 4 7 1 5 
3
5 4 2 
stdout
arr2 is a subset of arr1