package com.fishercoder.solutions;

import java.util.ArrayList;
import java.util.List;

/**
 * 1002. Find Common Characters
 *
 * Given an array A of strings made only from lowercase letters,
 * return a list of all characters that show up in all strings within the list (including duplicates).
 * For example, if a character occurs 3 times in all strings but not 4 times, you need to include that character three times in the final answer.
 *
 * You may return the answer in any order.
 *
 * Example 1:
 * Input: ["bella","label","roller"]
 * Output: ["e","l","l"]
 *
 * Example 2:
 * Input: ["cool","lock","cook"]
 * Output: ["c","o"]
 *
 * Note:
 *
 * 1 <= A.length <= 100
 * 1 <= A[i].length <= 100
 * A[i][j] is a lowercase letter
 */
public class _1002 {
  public static class Solution1 {
    public List<String> commonChars(String[] A) {
      int[][] charCount = new int[A.length][26];
      for (int i = 0; i < A.length; i++) {
        for (char c : A[i].toCharArray()) {
          charCount[i][c - 'a']++;
        }
      }
      List<String> result = new ArrayList<>();
      for (int i = 0; i < 26; i++) {
        while (charCount[0][i] != 0) {
          char c = (char) (i + 'a');
          boolean valid = true;
          charCount[0][i]--;
          for (int j = 1; j < A.length; j++) {
            if (charCount[j][i] == 0) {
              valid = false;
              break;
            } else {
              charCount[j][i]--;
            }
          }
          if (!valid) {
            break;
          } else {
            result.add("" + c);
          }
        }
      }
      return result;
    }
  }
}

@@ -642,19 +642,16 @@
 * Note:%0A
- *%0A
  * 1 %3C= 
@@ -751,16 +751,18 @@
 _1002 %7B%0A
+  
   public
@@ -787,16 +787,20 @@
 tion1 %7B%0A
+    
     publ
@@ -847,16 +847,22 @@
 %7B%0A      
+   
+   
 int%5B%5D%5B%5D 
@@ -896,16 +896,22 @@
 h%5D%5B26%5D;%0A
+      
       fo
@@ -937,32 +937,40 @@
 .length; i++) %7B%0A
+        
         for (cha
@@ -999,32 +999,42 @@
 ()) %7B%0A          
+         
+ 
 charCount%5Bi%5D%5Bc -
@@ -1042,16 +1042,24 @@
 'a'%5D++;%0A
+        
         
@@ -1066,24 +1066,36 @@
 %7D%0A      
+ 
-%7D%0A
+     %7D%0A   
       
+   
 List%3CStr
@@ -1127,16 +1127,22 @@
 st%3C%3E();%0A
+      
       fo
@@ -1162,32 +1162,40 @@
  i %3C 26; i++) %7B%0A
+        
         while (c
@@ -1213,24 +1213,34 @@
 %5Bi%5D != 0) %7B%0A
+          
           ch
@@ -1274,16 +1274,26 @@
         
+        
+  
 boolean 
@@ -1308,32 +1308,42 @@
 true;%0A          
+       
+   
 charCount%5B0%5D%5Bi%5D-
@@ -1347,32 +1347,42 @@
 i%5D--;%0A          
+     
+     
 for (int j = 1; 
@@ -1398,24 +1398,36 @@
 gth; j++) %7B%0A
+            
             
@@ -1450,24 +1450,38 @@
 %5Bi%5D == 0) %7B%0A
+              
             
@@ -1503,39 +1503,60 @@
 ;%0A              
+   
-break;%0A
+           break;%0A       
             %7D el
@@ -1543,32 +1543,37 @@
                 
+     
 %7D else %7B%0A       
@@ -1571,32 +1571,46 @@
 %7B%0A              
+            
+  
 charCount%5Bj%5D%5Bi%5D-
@@ -1616,32 +1616,66 @@
 --;%0A            
+            %7D%0A                    
 %7D%0A          %7D%0A  
@@ -1662,34 +1662,32 @@
     %7D%0A          
-%7D%0A
           if (!v
@@ -1698,39 +1698,58 @@
 ) %7B%0A            
+ 
-break;%0A
+           break;%0A       
           %7D else
@@ -1734,32 +1734,35 @@
                 
+   
 %7D else %7B%0A       
@@ -1746,32 +1746,44 @@
        %7D else %7B%0A
+            
             resu
@@ -1800,32 +1800,42 @@
 + c);%0A          
+  
+        
 %7D%0A        %7D%0A    
@@ -1828,24 +1828,32 @@
         
+ 
+       
 %7D%0A      
 %7D%0A      
@@ -1840,26 +1840,38 @@
     %7D%0A      
+ 
-%7D%0A
+     %7D%0A      
       return
@@ -1883,16 +1883,22 @@
 lt;%0A    
-%7D%0A
+    %7D%0A  
   %7D%0A%7D%0A

refactor 1002