fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. /* Name of the class has to be "Main" only if the class is public. */
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. // your code goes here
  11. String[] words=new String[]{"bella","label","roller"};
  12. String str=words[0];
  13. Map<Character,Integer>hmap=new HashMap<>();
  14. for(int i=0;i<str.length();i++){
  15. char c=str.charAt(i);
  16. hmap.put(c,hmap.getOrDefault(c,0)+1);
  17. }
  18. for(int i=1;i<words.length;i++){
  19. String newstr=words[i];
  20. Map<Character,Integer>freqmap=new HashMap<>();
  21. for(int j=0;j<newstr.length();j++){
  22. char c=newstr.charAt(j);
  23. freqmap.put(c,freqmap.getOrDefault(c,0)+1);
  24. }
  25. for(Character key:hmap.keySet()){
  26. if(freqmap.containsKey(key)){
  27. hmap.put(key,Math.min(hmap.get(key),freqmap.get(key)));
  28. }
  29. else{
  30. hmap.put(key,0);
  31. }
  32. }
  33. }
  34. List<String> list=new ArrayList<>();
  35. for(Character key:hmap.keySet()){
  36. if(hmap.get(key)>0){
  37. for(int i=0;i<hmap.get(key);i++){
  38. list.add(key+"");
  39. }
  40. }
  41. }
  42. System.out.println(list);
  43. }
  44. }
Success #stdin #stdout 0.14s 55572KB
stdin
Standard input is empty
stdout
[e, l, l]