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 int func(String s,String t){
  11. int n = s.length();
  12. HashMap<Character,Integer>map = new HashMap<>();
  13. for(int i=0;i<n;i++){
  14. char ch = s.charAt(i);
  15. map.put(ch,map.getOrDefault(ch,0)+1);
  16. }
  17. int mini = Integer.MAX_VALUE;
  18. for(int i=0;i<t.length();i++){
  19. char ch = t.charAt(i);
  20. int val = map.getOrDefault(ch,0);
  21. mini = Math.min(mini,val);
  22. }
  23. return mini;
  24. }
  25. public static void main (String[] args) throws java.lang.Exception
  26. {
  27. // your code goes here
  28. String s = "abacbc";
  29. String t = "bcad";
  30. System.out.println(func(s,t));
  31. }
  32. }
Success #stdin #stdout 0.04s 23124KB
stdin
Standard input is empty
stdout
0