• + 0 comments

    java

    public static int gemstones(List<String> arr) {
        // Write your code here
          int[] alpha = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
          int count = 0;
          int size = arr.size();
          for(String s : arr){
              char[] chars = s.chars()
                    .distinct()
                    .mapToObj(c -> String.valueOf((char) c))
                    .collect(Collectors.joining()).toCharArray();
                    
              for(int i=0;i<chars.length;i++){
                   
                 alpha[(int) (chars[i]-'a')]++; 
                           
                  if(alpha[(int) (chars[i]-'a')]==size){
                      count ++;
                  }
              }
          }
          return count;
        }