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.  
  14. Scanner sc=new Scanner(System.in);
  15. // size of 1st arr
  16. int n=sc.nextInt();
  17.  
  18. // size of 2nd arr
  19. int m=sc.nextInt();
  20.  
  21. int arr1[]=new int[n];
  22. int arr2[]=new int[m];
  23.  
  24. for(int i=0;i<n;i++)
  25. arr1[i]=sc.nextInt();
  26.  
  27. for(int i=0;i<m;i++)
  28. arr2[i]=sc.nextInt();
  29.  
  30. Set<Integer> s=new HashSet<>();
  31. for(int ele: arr1)
  32. s.add(ele);
  33.  
  34. boolean flag=true;
  35. for(int ele:arr2)
  36. {
  37. if(!s.contains(ele))
  38. {
  39. flag=false;
  40. break;
  41. }
  42. }
  43.  
  44. if(flag)
  45. System.out.println("Arr2 is a subset of arr1");
  46. else
  47. System.out.println("arr2 is not a subset of arr1");
  48.  
  49. }
  50. }
Success #stdin #stdout 0.17s 56608KB
stdin
5
4
 1 2 3 5 8 
1 2 3 8
stdout
Arr2 is a subset of arr1