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. int arr[] = {1,2,4,1};
  15. int arr2[] = {2,3};
  16.  
  17. int n = arr.length;
  18. int n2 = arr2.length;
  19.  
  20. Set<Integer> st = new HashSet<>();
  21. for(int i =0;i<n;i++){
  22. st.add(arr[i]);
  23. }
  24.  
  25. for(int j=0;j<n2;j++){
  26. if(!st.contains(arr2[j])){
  27. System.out.println("Array 2 is not a subset of array 1");
  28. return ;
  29. }
  30. }
  31. System.out.println("Array2 is a subset of array 1");
  32. }
  33. }
Success #stdin #stdout 0.08s 54544KB
stdin
Standard input is empty
stdout
Array 2 is not a subset of array 1